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 trialJoseph Turbin
621 PointsStep 4 of 4: Declare a String variable named intAsString
I cannot figure out how to do this step. Any help?
5 Answers
Justin Horner
Treehouse Guest TeacherHello Joseph,
The challenge is to use Integer.toString to convert the randomNumber variable.
For example
String intString = Integer.toString(myIntVariable);
Check out the documentation for more info.
I hope this helps.
Marcus Vieira
7,877 PointsHi Joseph!
See if this helps:
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = // call the Integer class that has a static method called `toString` and send `randomNumber` as an argument
Marcus Vieira
7,877 PointsJoseph,
You should be passing in the variable that you want to convert from Integer
to String
, in this case, randomGenerator
Integer.toString(variableYouWantToConvert);
I hope this helps!
Joseph Turbin
621 PointsThank you both for your answers. I think I understand what I'm supposed to be accomplishing, just can't figure out how to make it correct. Here's what I've got:
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = Integer.toString(??);
Justin Horner
Treehouse Guest TeacherYou're welcome!
Where you have question marks, you need to pass the randomNumber variable. This will give the desired result of returning a string representation of your randomNumber variable.
I hope this helps.
Joseph Turbin
621 PointsWow.. I swear I tried that. Thank you again!