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 trialCortney Burgess
10,758 PointsDo not understand..
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.
what is wrong? ```Random randomGenerator = new Random(); int randomNumber = randomGenerator. nextInt(10); answer = Integer. toString(randomNumber);
12 Answers
Jason Anello
Courses Plus Student 94,610 PointsI think that you're not supposed to have a space after Integer.
Paul Stevens
4,125 PointsHello,
In this code you have a space between Integer. and toString. Try removing that space.
You have:
answer = Integer. toString(randomNumber);
You want this:
answer = Integer.toString(randomNumber);
Hope this helps, if not let me know.
Paul :)
Cortney Burgess
10,758 PointsRandom randomGenerator = new Random();
int randomNumber = randomGenerator. nextInt(10);
answer= Integer.toString(randomNumber);
Cortney Burgess
10,758 Pointsdid not help
Jason Anello
Courses Plus Student 94,610 PointsSorry, there's more errors than initially thought.
You also have a space after randomGenerator.
It was hard to tell from original post because that's where the line break occurred.
Also, your last line of code doesn't match up with the directions for task 4. It's saying, Declare a String variable named intAsString
Paul Stevens
4,125 PointsOk, I also notice that is asking you to store the result in the "intAsString" variable, at the moment this code is storing it in the variable "answer"
You have:
answer= Integer.toString(randomNumber);
Try this instead:
intAsString = Integer.toString(randomNumber);
Paul :)
Cortney Burgess
10,758 PointsRandom randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
intAsString = Integer.toString(randomNumber);
Cortney Burgess
10,758 Pointsstill saying syntax error
Jason Anello
Courses Plus Student 94,610 PointsYou didn't declare it as a String
type.
Paul Stevens
4,125 PointsTry this
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString; //declare the variable
intAsString = Integer.toString(randomNumber); //assign the value to the string
Paul :)
Paul Stevens
4,125 PointsOr you maybe can combine the lines to this:
String intAsString = Integer.toString(randomNumber);
Paul :)
william parrish
13,774 Points^ last line should read like this
String intAsString = Integer.toString(randomNumber);