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

Phil White
PLUS
Phil White
Courses Plus Student 9,519 Points

Stuck on this question in Android development

Declare a String variable named intAsString. Convert the randomNumber integer to a String value and store it in the intAsString variable. Hint: "Moosh" them together like in the video!

Phil White
Phil White
Courses Plus Student 9,519 Points

This is the code you start with

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

2 Answers

Kate Hoferkamp
Kate Hoferkamp
5,205 Points

When it says to "moosh them together" it wants you to concatenate it so that the String value overrides the int and automatically converts it to a String value.

All you have to do is

String intAsString = "" + randomNumber;
Joseph Greevy
Joseph Greevy
4,990 Points

I may be getting mixed up with programming languages so forgive me if I am wrong but i believe the task is accomplished like so:

Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(3);
String intAsString = string(randomNumber);