Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

what is the answer?

what is the answer to this? i am always getting it wrong.

RandomTest.java
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(word.length);
String word = "intAsString";
String words = "";
words = word [randomNumber];

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Ok I*m not sure where you're getting the "word" thing from, but I will post the code I used to pass the challenge and then go through it.

Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = String.valueOf(randomNumber);

First, we create a new instance of a Random and assign it to a variable named randomGenerator Secondly, we create a new integer variable named randomNumber and use our randomGenerator along with the .nextInt method to return an integer between 0 and 9 and store it there. Thirdly, we take that integer and run it through the String.valueOf method to turn our integer into a string and store it in a new string variable named intAsString

Hope this clears things up!