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 trialEric Dotson
1,933 PointsBummer! Check the parameter you're using for 'nextInt()'. Hint: 0 through 9 is a total of 10 choices.
this is the error I keep getting in this is my code what am I doing wrong?
Random randomGenerator = new Random();//Constructa new Random number generator int randomNumber = randomGenerator.nextInt(1)
3 Answers
Stone Preston
42,016 Pointsyou need a generate a number between 0 and 9. you are currently only generating a number between 0 and 1 exclusively (so only 0 will be generated)
if I wanted to generate a number between 0 and 5 I would use
int randomNumber = randomGenerator.nextInt(6);
Eric Dotson
1,933 PointsI tried that i went threw every number between 0 and nine it still gave that error
Stone Preston
42,016 Pointsthe number you pass to the method is exclusive. you said youve tried 0 through 9, try using 10.
Eric Dotson
1,933 Pointsthanks it worked