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

Step 4 of 4: Declare a String variable named intAsString

I cannot figure out how to do this step. Any help?

5 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello 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
Marcus Vieira
7,877 Points

Hi 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
Marcus Vieira
7,877 Points

Joseph,

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!

Thank 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
Justin Horner
Treehouse Guest Teacher

You'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.

Wow.. I swear I tried that. Thank you again!