if ( value == 399 ) System.out.println("Correct Value"); else System.out.println("Wrong Value");
In the following, X
and Y
represent numbers that can be compared.
Comparison | Equivalent |   | Comparison | Equivalent |
---|---|---|---|---|
!(X < Y) | X >= Y | !(X >= Y) | X < Y | |
!(X > Y) | X <= Y | !(X <= Y) | X > Y | |
!(X == Y) | X != Y | !(X != Y) | X == Y |
Usually if you have a comparison that uses a NOT operator, replace it with an equivalent comparison that does not use a NOT.
Rewrite the following if
statement:
if ( !(car.price > 8000 ) ) System.out.println("Affordable"); else System.out.println("Too Expensive!");