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 trial

Android Build a Simple Android App (2014) Basic Android Programming Using the Random Class

Thomas Beaudry
Thomas Beaudry
29,084 Points

Creating a String variable, the intAsString variable??

This one assignment has been haunting me since Saturday, lol.

RandomTest.java
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = randomNumber = "";
Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi 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:

  Random randomGenerator; //this is already in the challenge
  randomGenerator = new Random();// dont need to declare Random again
  int randomNumber = randomGenerator.nextInt(10);
  String intAsString = Integer.toString(randomNumber);

Hope it helps, let us know if you need more help

Grigorij

2 Answers

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi 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
Thomas Beaudry
29,084 Points

Thanks Grigorij, I just tried it the way you showed but no luck, appreciate your input though!

Thomas Beaudry
Thomas Beaudry
29,084 Points

Grigorij, 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
Grigorij Schleifer
10,365 Points

Hey 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
Thomas Beaudry
29,084 Points

Grigorij, 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
Grigorij Schleifer
10,365 Points

Java is not very beginnerfriendly, but it is worth it !!!

Ask here in forum and we will help you get the challenges done :)