This site requires JavaScript, please enable it in your browser!
Greenfoot back
Barador
Barador wrote ...

2012/8/27

Integer into String

Barador Barador

2012/8/27

#
Hi! I want to generate a random number into an integer andd then diaplay it into my text bubble as string. How can I get the Number in the Integer into the String?
erdelf erdelf

2012/8/27

#
write this:
String str = yourInt +"";
Zamoht Zamoht

2012/8/27

#
String test1 = "";
int test2 = 150;
test1 = String.valueOf(test2);
Is one way.
Zamoht Zamoht

2012/8/27

#
Or
String test1 = "";  
int test2 = 150; 
test1 = Integer.toString(test2);
Barador Barador

2012/8/27

#
@erdelf It just puts out a "0" @Zamoht He sais he needs an identifier behind the test1 in line 3
Zamoht Zamoht

2012/8/27

#
You have to declare the string first like: "String test1 = "";" or you can do it in one line "String test1 = String.valueOf(test2);"
Barador Barador

2012/8/27

#
Ok thanks it works :)
erdelf erdelf

2012/8/27

#
btw. my way works, I tried it
Zamoht Zamoht

2012/8/27

#
I tried as well and it works. (:
You need to login to post a reply.