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 trialTim Huurdemam
Courses Plus Student 323 PointsI am stuck
I just can't figure out how to do this challenge. I think I got it right but it says that I am wrong. Does anybody know how to do this challenge? Thanks
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = "";
randomNumber + "";
2 Answers
Harry James
14,780 PointsHey Tim!
You were close - you're setting intAsString to a blank String but instead, we want to set it to the integer in its String form.
Ben showed you earlier how we can convert an integer to a String just by concatenating a blank String to the end of it. Do you remember how to do that? Give it a go ;)
If you need a refresher, check out the Previous Video at the 03:10 marker.
If you get stuck along the way, leave me a message here and I'll help you out a bit more :)
Pedro Sousa
Python Development Techdegree Student 18,546 PointsHello Tim,
doing this
String intAsString = "";
randomNumber = "";
your just creating an empty string and assigning another empty string to randomNumber (which, actually will not work, since randomNumber is an integer.
What the challenge is asking you to do is to write the number to the string variable. I didn't check the videos, but by "moosh" I think you're actually meant to just concatenate the number to a string;
Does this help?
Tell me if it doesn't.
Tim Huurdemam
Courses Plus Student 323 PointsI don't really get what you mean, I am sorry if I am a bit of a noob. I'm just getting started. I tried changing the = to a +, but this didn't work. Was this your hint or did I get it wrong? Thanks for the quick reply btw
Tim Huurdemam
Courses Plus Student 323 PointsTim Huurdemam
Courses Plus Student 323 PointsI am thankfull that you replied so quick, and I think I know what you mean. I tried changing the = to a +, but this didn't work. Did you ment to do this, or did I got your hint wrong?
Harry James
14,780 PointsHarry James
14,780 PointsHey Tim!
You still need the
=
to define the variable but after that, we want to set the value to the integer + the blank String. This forces Java to convert the integer to a String :)Tim Huurdemam
Courses Plus Student 323 PointsTim Huurdemam
Courses Plus Student 323 PointsI think I get what you mean, and I tried it another way: Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt(10); String intAsString = Int.toString(randomNumber); This worked. Thanks for your help!!