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

2021/6/25

int Letters & Check boolean is true?

Gabe1098 Gabe1098

2021/6/25

#
how do I put letters in ints and this code is probably wrong so can you tell me the real way to do this
public Boolean test = true;

if (test = true) {

}
I'm talking about the
if (test = true) {

}
if this is wrong can you tell me the correct way of doing that?
danpost danpost

2021/6/25

#
Use double equal signs to test if two values are the same (or two references refer to the same object). Change "Boolean" to "boolean" and use "==" instead of "=".
Gabe1098 Gabe1098

2021/6/25

#
danpost wrote...
Use double equal signs to test if two values are the same (or two references refer to the same object). Change "Boolean" to "boolean" and use "==" instead of "=".
thanks!!! what about putting letters in ints?
danpost danpost

2021/6/25

#
Gabe1098 wrote...
what about putting letters in ints?
Not sure what you mean. If you are talking about an int containing the numeric asciii code of an alpha character:
int letterA = "A".charAt(0);
// or
int letterA = 'A';
// or
int letterA ='\u0041';
// or
int letterA = (char)65;
All of the above set letterA to a value of 65, the character code for the letter A.
Gabe1098 Gabe1098

2021/6/25

#
danpost wrote...
Gabe1098 wrote...
what about putting letters in ints?
Not sure what you mean. If you are talking about an int containing the numeric asciii code of an alpha character:
int letterA = "A".charAt(0);
// or
int letterA = 'A';
// or
int letterA ='\u0041';
// or
int letterA = (char)65;
All of the above set letterA to a value of 65, the character code for the letter A.
I might be dumb here lol I don't know much about ints but I mean this
int test = Cool;
Super_Hippo Super_Hippo

2021/6/25

#
That seems to be a String.
String test = "Cool";
int is only used for whole numbers.
Gabe1098 Gabe1098

2021/6/25

#
Super_Hippo wrote...
That seems to be a String.
String test = "Cool";
int is only used for whole numbers.
ohh thanks!
Gabe1098 Gabe1098

2021/6/25

#
Super_Hippo wrote...
That seems to be a String.
String test = "Cool";
int is only used for whole numbers.
Thank you it works!
You need to login to post a reply.