Not part of the answer
Hello all, I'm having problem with trying to catch a wrong reply.
Well i got anif loop to it but, at the end of the little program i get the statement of the "wrong reply catcher".
if(reply.equalsIgnoreCase("F")){
calcFah();
}if(reply.equalsIgnoreCase("C")){
calccel();
}if(reply !="Y"||reply!="N"){
System.out.println("This is not a choice for the above question.");
}
Thanks
> if(reply != "Y"||reply!="N")
1) Quit comparing String values like that. You didn't do it on your other statements, so why start doing it here? Use the equals() or equalsIgnoreCase() method similar to where you did that before.
2) The logic is messed up. Reply is ALWAYS going to be something other than "Y" OR "N". If it's "Y", it's not equal to "N", so the above would evaluate true. If it's not "Y", the above still evaluates true.
oh sorry i added it wrong
if(reply.equalsIgnoreCase("F")){
calcFah();
}if(reply.equalsIgnoreCase("C")){
calccel();
}if(reply != "F"||reply!="C"){
System.out.println("This is not a choice for the above question.");
}
The wrong reply catcher is an if loop that will see if i entered something other than "F" or "C". Yes i have tried if-else. I've might have use it wrong.
> 1) Quit comparing String values like that. You didn't
> do it on your other statements, so why start doing it
> here? Use the equals() or equalsIgnoreCase() method
> similar to where you did that before.
> 2) The logic is messed up. Reply is ALWAYS going to
> be something other than "Y" OR "N". If it's "Y", it's
> not equal to "N", so the above would evaluate true.
> If it's not "Y", the above still evaluates true.
Ok i'm going to use equals() from now on. How would i go about getting the "wrong" answer?
Thanks Warnerja
> The wrong reply catcher is an if loop that will see
> if i entered something other than "F" or "C". Yes i
> have tried if-else. I've might have use it wrong.
I don't see any elses? With an else you would not need the last if statement.
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/if.html
if(reply.equalsIgnoreCase("F")){
calcFah();
}else if(reply.equalsIgnoreCase("C")){
calccel();
}else{
System.out.println("This is not a choice for the above question.");
}
Do you mean like this?
Let me try it out.
*Thanks Warneja and Zadok it works.
Message was edited by:
Davey_Vargas