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 trialwaylon roach
371 PointsI have a question about the Code Challenge:Using the Random class. Not understanding the last part. Please help.
"Declare a String variable named intAsString. Convert the randomNumber integer to a String value and store it in the intAsString variable. Hint: "Moosh" them together like in the video!"
I've watched the video 4 time now. Still not understanding what to do.
Random randomGenerator;
1 Answer
Ryan Ruscett
23,309 PointsHey,
There are a couple of ways to do it. Except the easiest way is this. If you take an integer and you add a string to it. It will put the entire variable in string form. So it converts the int to a string for you.
Random randomGenerator;
randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = randomNumber + "";
OR
----Integer.toString(number)----
String intAsString = Integer.toString(randomGenerator
OR
----String.valueOf(number)----
String intAsString = String.valueOf(randomNumber )
All three of those work in different ways, but produce the same result.
Let me know if you have any questions on any one specific one and I can definitely elaborate.
Thanks!
waylon roach
371 Pointswaylon roach
371 PointsThank you! I did the first one you have there( String intAsString = randomNumber + ""; ), but for some reason it didn't work the first time.