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 (2014) Basic Android Programming Using the Random Class

how would I declare a string variable name intAsString after converting the randomNumber integer to aString value

How would i go for this challenge?declare a string variable name intAsString.conver the randomNumber integer to a string value and store it in the intAsString variable.hint" Moosh" them together

RandomTest.java
Random randomGenerator=new Random(); // Construct a new Random number generator
int randomNumber=randomGenerator.nextInt(10);
(!intAsString=(Integer.toString(randomNumber))){

THANK YOU A LOT.IT HAS HELPED

1 Answer

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hola,

Yeah moosh them together lol. Remember, you can convert an Integer to a string by using contatenate if I spelled that right lol. Like this

WRONG - the top of the code already defines Random. 
Random randomGenerator;  //no need to clarify again in your next statement. Just remove the Random from it like below.

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

THIS
String intAsString = randomNumber + "";

NOT
(!intAsString=(Integer.toString(randomNumber))){

toString is more of a print method override collections or obtaining values from Scanner or whatever lots of stuff. I would convert a string to integer by either Integer.parse or by mooshing them together. Mooshing them is top choice when working in android.

That code should get you all the way through when fixed to look like the example above, let me know if you have any issues or if this worked for you.

Thanks