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 Basic Android Programming Using the Random Class

the RandomTest.java isn't accepting my value

Random randomGenerator = new Random(); int randomNubmer = randomGenerator.nextInt(8); // the question was to use a list from 0 to 9 // i did but its says Bummer

RandomTest.java
Random randomGenerator = new Random();
int randomNubmer = randomGenerator.nextInt(8);

1 Answer

andren
andren
28,520 Points

The random number's nextInt method generates a number between 0 and up to (but not including) the number you specify. This means that if you specify 8 you are telling nextInt to generate a number between 0 and 7.

In order to generate a number between 0 and 9 you therefore need to pass in 10 as the argument.

thanks that helps