Jezuit
asked on
Comparing String Values
I seem to think this should be simple, but it's not... What I'm doing is simple: I want to compare a user's input (Y/N) to a set value and compare them as an if statement. For example:
sAnswer = Console.readString("Would you like to do it again (Y/N) ? ");
if (sAnswer == "Y") {
[first thing to do;]
[second thing to do;]
}
else {
[first thing to do if not Y;]
[second thing to do if not Y;]
}
Seems simply enough, but when I try to do that, I will specifically put in "N", and it'll still do the Y statements. I even put a System.out.println(sAnswer ); statement in there, and it tells me exactly what I put (N), which is not Y, but it still continues to do Y anyway. Is there anything I can do to compare strings??
Jez
sAnswer = Console.readString("Would you like to do it again (Y/N) ? ");
if (sAnswer == "Y") {
[first thing to do;]
[second thing to do;]
}
else {
[first thing to do if not Y;]
[second thing to do if not Y;]
}
Seems simply enough, but when I try to do that, I will specifically put in "N", and it'll still do the Y statements. I even put a System.out.println(sAnswer
Jez
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
damn you were fast :p
>>Or even better still (avoiding null pointers);
True...
True...
"Y".equalsIgnoreCase(sAnsw