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 trialDerrick Shepherd
4,861 PointsI Can't Seem To Get This!
I'm In The Android Development Track And I'm Having Trouble With This Question. "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."
My Code So Far Looks Like This But It's Incorrect:
String intAsString; Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt("");
I Don't Know What I'm Doing Wrong...
2 Answers
Stone Preston
42,016 PointsOk so youve declared your string variable. That looks good. However you still need to assign that string variable the value of your randomNumber variable (youll need to use the Integer.toString() method and pass in your randomNumber variable as an argument to convert it to a string)
For example, if I wanted to assign a string variable called someString the value of an integer variable called someInt I would use
int someInt = 1;
String someString = Integer.toString(someInt);
Derrick Shepherd
4,861 PointsThank You For The Timely Response Stone! Great Explanation (Thumbs Up!)
Derrick Shepherd
4,861 PointsDerrick Shepherd
4,861 PointsThank You For The Timely Response Stone! Great Explanation (Thumbs Up!)
Stone Preston
42,016 PointsStone Preston
42,016 Pointsno problem : )