Android Build a Simple Android App Basic Android Programming Using the Random Class

i dont know what you mean in the last task

what should i do i don't understand

RandomTest.java
Random randomGenerator = new Random();
int String = string.nextInt();
String intAsString = (String);

1 Answer

Michael Nock
Michael Nock
Android Development Techdegree Graduate 16,017 Points

First you need to create a new Random object, which you do. Where you're having trouble is in the next step. You need to create a new integer called "randomNumber". You've named your integer "String", which is already a Java keyword for string objects. Change the name to randomNumber. Your next problem is getting the random integer. To do this, you need to use the Random object you created in the first line called "randomGenerator". Random objects have a method attached to them called "nextInt()" which you can use by simply typing a dot after the variable (eg. "randomGenerator.nextInt()"). After this, you have to limit the random integer to a value between 0 and 9. You can do this by adding an argument to the "nextInt()" method. Lastly, you need to convert that integer into a string in a new String variable (which you have and have named correctly). I believe in the video they showed us one way to do this by taking an integer and adding it to an empty string (eg. "" + 19).

So to sum up:

  1. Properly name your int variable.
  2. Make sure you're using the proper variable to get the random integer from "nextInt()".
  3. Limit the random integer to a value between 0 and 9 by adding an argument to the nextInt() method.
  4. Convert the random integer to a string by adding it with an empty string ("").

If anything's still not clear, just let me know :)