compound if statement
Can someone why this isn't working. Only the 1st equation is evaluated.
String attributeToChange.=" "
if(!attributeToChange.equals("a") |
!attributeToChange.equals("b") |
!attributeToChange.equals("c)){
attributeToChange= "this var is NOT equal to a , b or c";
}else{
attributeToChange= "this var IS equal to a , b or c";
}
For example:String myCar = "chevy";
if (myCar.equals("honda") || myCar.equals("toyota"))// if (false or false) evaluates to false
{
System.out.println("1. This shouldn't print");
}
if (myCar.equals("honda") || myCar.equals("chevy"))// if (false or true) evaluates to true
{
System.out.println("2. This will print");
}
if (!myCar.equals("honda") || !myCar.equals("toyota")) // if (true or true) evaluates to true
{
System.out.println("3. This will print");
}
if (!myCar.equals("honda") || !myCar.equals("chevy")) // if (true or false) evaluates to true
{
System.out.println("4. This will print");
}
this works
String attributeToChange.=" "
if(!attributeToChange.equals("a") &&
(!attributeToChange.equals("b") )&&
(!attributeToChange.equals("c))) {
attributeToChange= "this var is NOT equal to a , b or c";
}else{
attributeToChange= "this var IS equal to a , b or c";
}