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 trialThomas Beaudry
29,084 PointsCreating a String variable, the intAsString variable??
This one assignment has been haunting me since Saturday, lol.
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = randomNumber = "";
2 Answers
Grigorij Schleifer
10,365 PointsHi Thomas,
you can convert the primitive type int to String.
here is the way you can do it:
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = Integer.toString(randomNumber);
Integer is a wrapper class that contains methods like toString() that accepts a int variable
Grigorij
Thomas Beaudry
29,084 PointsThanks Grigorij, I just tried it the way you showed but no luck, appreciate your input though!
Thomas Beaudry
29,084 PointsGrigorij, you are THE man, I do see where ur coming from now, You made it all very clear now...you should be the teacher here! Thank you for taken the time out and helping me to understand it, if u need my help anytime feel free to ask me, have a great day!
Grigorij Schleifer
10,365 PointsHey Thomas,
thank you so much :) I do the java track for now and if I am fit with it I will focus on android. Java is quite difficult for a programming beginner, but I love to kick my head and try to understand the concepts. Keep on coding ....
Grigorij
Thomas Beaudry
29,084 PointsGrigorij, You know that makes a lot of sense, I jumped directly into "Android" without any prior java experience(java illeterate) I am holding off on Android until I have some know ho⦠great chating with u happy coding!
Grigorij Schleifer
10,365 PointsJava is not very beginnerfriendly, but it is worth it !!!
Ask here in forum and we will help you get the challenges done :)
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHi Thomas,
I pasted the code below in the challenge. It works. DonΒ΄t forget to remove the first Random (class name) from the line
Random randomGenerator = new Random();
it shoul look this way:
Hope it helps, let us know if you need more help
Grigorij