Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App with Java Basic Android Programming Using the Random Class

Jack Gugolz
Jack Gugolz
280 Points

Build a Simple Android App with Java - RandomTest Challenge Task 4 of 4 help

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

Cant figure out the answer to this statement. Need help to continue the course. Thanks

RandomTest.java
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(intAsString);

how

1 Answer

Hi there,

The last task requires you to create a new variable called intAsString of type String. Assign into that the result of adding an empty string to randomNumber.

Make sense?

Steve.

Jack Gugolz
Jack Gugolz
280 Points

I tried:

Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(intAsString);
String intAsString = randomnumber + "";

Did not work so what am I missing?

Don't put intAsString in your nextInt method. Pass in the number 10.

Jack Gugolz
Jack Gugolz
280 Points

Made the change:

Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = randomnumber + "";

Still some problem though

Your variable is called randomNumber not randomnumber. You typo'd the last line. :smile:

Jack Gugolz
Jack Gugolz
280 Points

There we go! Thank you dude :)

If you copy your code in and hit the Preview button, it'll show you where your syntax errors are. This one showed up in there. Might help you progress more quickly rather than waiting for a reply in here.

Glad you got going again! :+1: