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!
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
i dont know what you mean in the last task
what should i do i don't understand
Random randomGenerator = new Random(); int String = string.nextInt(); String intAsString = (String);
Michael NockAndroid Development Techdegree Graduate 16,018 Points
First you need to create a new Random object, which you do. Where you're having trouble is in the next step. You need to create a new integer called "randomNumber". You've named your integer "String", which is already a Java keyword for string objects. Change the name to randomNumber. Your next problem is getting the random integer. To do this, you need to use the Random object you created in the first line called "randomGenerator". Random objects have a method attached to them called "nextInt()" which you can use by simply typing a dot after the variable (eg. "randomGenerator.nextInt()"). After this, you have to limit the random integer to a value between 0 and 9. You can do this by adding an argument to the "nextInt()" method. Lastly, you need to convert that integer into a string in a new String variable (which you have and have named correctly). I believe in the video they showed us one way to do this by taking an integer and adding it to an empty string (eg. "" + 19).
So to sum up:
- Properly name your int variable.
- Make sure you're using the proper variable to get the random integer from "nextInt()".
- Limit the random integer to a value between 0 and 9 by adding an argument to the nextInt() method.
- Convert the random integer to a string by adding it with an empty string ("").
If anything's still not clear, just let me know :)