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 trialJigar Patel
1,133 PointsTrying to limit the range of the randomNumber variable.
I'm not sure what I am doing wrong here. I added an integer "(1)" to limit the range, yet when submitting the code, it gives me a "Bummer!" and tells me I need to put in an integer between 0-9.
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(1);
3 Answers
Ben Deitch
Treehouse TeacherIt wants you to generate a random number between 0-9. Not pick a an integer 0-9.
Tanner Marshall
13,717 PointsHi Jigar!
Do you have the full question? I'm wondering if it's asking to output an integer between 0-9. If that's the case, your code should be something like this:
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
This'll output the next int value between 0 and 9, since the specified value (10) will be excluded from the range.
Hope that helps!
Jigar Patel
1,133 PointsThank you community! This makes much more sense. +1 to all who pitched in!
Samuel Havard
6,650 PointsSamuel Havard
6,650 PointsIt really isn't worded well, but what its asking for is not an input between 0 and 9, its asking you to limit the random numbers returned from the method between those numbers, so you need to have .nextInt(10). This allows for random numbers between 0 and 9 to be returned.