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

reginald everett
PLUS
reginald everett
Courses Plus Student 1,862 Points

please help!!!!!

im stuck on this part of the code challenge

"Now limit the range of the randomNumber variable from 0 to 9. Use the version of 'nextInt()' that has a parameter that specifies how many numbers to choose from."

i input this data

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

and it still says im wrong!!

make randomGenerator.nextInt(9) to randomGenerator.nextInt(10)

Because Random 0 to 9 counts to 10.

2 Answers

Stone Preston
Stone Preston
42,016 Points

try using

 int randomNumber = randomGenerator.nextInt(10)

IIRC the argument passed to the nextInt function is exclusive, so you will get 0-9 by passing in 10, but only 0-8 if you pass in 9.

also you are missing the data type of your answer variable at this line

 answer = Integer.toString(randomNumber);

you need to declare it as a String

poop