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 trialTakudzwa Chauruka
488 Pointsneed help with android
am to convert an int to a String
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = new String(randomNumber);
5 Answers
Steve Hunter
57,712 PointsHi there,
Just add an empty string, ""
, onto randomNumber
and assign that into intAsString
. So, start by declaring String intAsString
as you have done, then to the right of the equals, perform the addition.
Steve.
Steve Hunter
57,712 PointsI've just seen your other post. You are on a completely different course to the one this thread refers to! You're doing the Kotlin course. That'll be why this thread isn't helping you.
Steve Hunter
57,712 PointsI have answered your question in the correct thread with a solution to the code challenge.
Enyang Mercy
Courses Plus Student 2,339 PointsSteve please help. Code won't run!!!!!!!!!!!!!!!!!!
import java.util.Random
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = randomNumber + ""
Steve Hunter
57,712 PointsYou need a semi-colon at the end of the last line. And remove the import
line - you don't need that as the challenge provides the necessary libraries.
Steve.
Enyang Mercy
Courses Plus Student 2,339 PointsThanks so much Steve still won't compile. I'm so fed up, i have tried over 4 different methods ERROR; 'random number' should be a string
Steve Hunter
57,712 PointsCan you post your code again - I'll see what the issue is.
Steve.
Enyang Mercy
Courses Plus Student 2,339 PointsRandom randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = randomNumber + "";
i remove the import as u instructed
Steve Hunter
57,712 PointsThat code is fine and passes the challenge. Maybe refresh the browser.
Takudzwa Chauruka
488 PointsTakudzwa Chauruka
488 Pointshey Steve
am kind of lost there. if you can do an example that will be great. thanks
Takudzwa
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsSure! First, declare your String as you have done. Then after the equals sign put
randomNumber + "";
.Steve.