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 trialChey Mike
478 PointsString variable
Create a String variable named intAsString. Convert the randomNumber integer to a String value and store it in the intAsString variable.
Random randomGenerator = new Random();
Random randomNumber = new Random();
int RandomNumber = randomGenerator.nextInt(10);
String variable = "inAsString";
4 Answers
Anson Tio
5,448 PointsLet's solve it step by step.
-
"Create a String variable named intAsString." In Java, to create a String type variable.
// Example // String <variableName> = "<inputString>" // remember double quotes for a string value String aString = "Hello"; // or String anotherString = ""; // you can declare a variable without assigning any value String yetAnotherString;
-
"Convert the randomNumber integer to a String value" Please have a look on java documentation link I provided https://docs.oracle.com/javase/tutorial/java/data/converting.html .Since randomNumber is an integer, We can use toString() function from Integer class.
String randomNumberInString = Integer.toString(randomNumber);
-
"store it in the intAsString variable." Since the question asked you to store it in "intAsString" variable, we can do this
String intAsString = Integer.toString(randomNumber);
Hope this helps :D
Chey Mike
478 PointsQUESTION:-
Create a String variable named intAsString. Convert the randomNumber integer to a String value and store it in the intAsString variable. Hint: Add them together like in the video!
Thank you for your response!! but unfortunately it didnt work. :( I am having a really hard time understanding this part. the video had some use of a plus sign. i dont quiet get it.
LINE OF CODE FOR PREVIOUS QUESIONS:-
Random randomGenerator = new Random (); Random randomNUmber = new Random (); int RandomNumber = randomGenerator.nextInt(10);
(THE STRING CODE GOES HERE)
can you use the ACTUAL name of the string i have to use for the example please in regards to the question?. for example if it was a question posted to you how would you answer?.
thanks much
Anson Tio
5,448 PointsMaybe you can try this one
// base on your code above
Random randomGenerator = new Random();
Random randomNumber = new Random();
int RandomNumber = randomGenerator.nextInt(10);
// I just noticed that you mentioned about plus sign, so maybe try this
String intAsString = randomNumber + "";
Chey Mike
478 PointsHaha thanks mate
Chey Mike
478 PointsChey Mike
478 Pointshelp me please, i am stuck here. i am new to this coding and this is a task to complete before i can proceed