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

[835 byte] By [Davey_Vargasa] at [2007-11-26 18:28:30]
# 1
I don't know what the "wrong reply catcher" is, but have you tried if...else?
Djaunla at 2007-7-9 6:02:41 > top of Java-index,Java Essentials,New To Java...
# 2

> 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.

warnerjaa at 2007-7-9 6:02:41 > top of Java-index,Java Essentials,New To Java...
# 3

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.

Davey_Vargasa at 2007-7-9 6:02:41 > top of Java-index,Java Essentials,New To Java...
# 4

> 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

Davey_Vargasa at 2007-7-9 6:02:41 > top of Java-index,Java Essentials,New To Java...
# 5

> 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

zadoka at 2007-7-9 6:02:41 > top of Java-index,Java Essentials,New To Java...
# 6
You apparently want (pseudo-code):if it's "F" do F logicelse if it's "C" do C logicelse do wrong input logicend-ifUse appropriate "else" statements.
warnerjaa at 2007-7-9 6:02:41 > top of Java-index,Java Essentials,New To Java...
# 7

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

Davey_Vargasa at 2007-7-9 6:02:41 > top of Java-index,Java Essentials,New To Java...