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

Android Build a Simple Android App (retired 2014) Learning the Language Objects and Random Numbers

Do 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

I think that you're not supposed to have a space after Integer.

Paul Stevens
Paul Stevens
4,125 Points

Hello,

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 :)

Random randomGenerator = new Random(); int randomNumber = randomGenerator. nextInt(10); answer= Integer.toString(randomNumber);

did not help

Sorry, 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
Paul Stevens
4,125 Points

Ok, 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 :)

Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
intAsString = Integer.toString(randomNumber);

still saying syntax error

You didn't declare it as a String type.

Paul Stevens
Paul Stevens
4,125 Points

Try 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
Paul Stevens
4,125 Points

Or you maybe can combine the lines to this:

String intAsString = Integer.toString(randomNumber);

Paul :)

william parrish
william parrish
13,774 Points

^ last line should read like this

String intAsString = Integer.toString(randomNumber);