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
Robert Yalda
389 PointsObjects and Random Numbers Challenge Part 4
Declare a String variable named intAsString. Convert the randomNumber integer to a String value and store it in the intAsString variable. Hint: Use the toString() method of the Integer class.
I hit a wall on this one guys. If you can give me some hints as to where to start I would appreciate it. Thanks!
3 Answers
samiff
31,206 PointsYou would think you might try:
intAsString = randomNumber.toString();
But you need something like:
Random randomGenerator;
randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString;
intAsString = Integer.toString(randomNumber);
I had one Java course so I may be wrong, but I think an integer is a primitive data type, meaning it isn't an object which has methods of its own. That's why you have to use the associated Integer class and one of its methods in this situation.
Ben Jakuben
Treehouse TeacherAh, just found this thread after replying in the other one. @Sam, thanks for chiming in! Hope that gave @Robert what he needed!
Robert Yalda
389 PointsThank you both very much! This helped a lot.