go to previous page   go to home page   go to next page hear noise highlighting

Answer:

if ( value == 399 )
  System.out.println("Correct Value");
else
  System.out.println("Wrong Value");

Equivalent Relational Expressions

Usually if you have an expression that uses a NOT operator, replace it with an equivalent comparison that does not use a NOT. If this is not possible, rewrite the expression so that the NOT applies to the smallest subexpression possible.

In the following, X and Y represent numbers that can be compared.


ExpressionEquivalent ExpressionEquivalent
!(X < Y)X >= Y   !(X >= Y) X < Y
!(X > Y)X <= Y   !(X <= Y) X > Y
!(X == Y)X != Y   !(X != Y) X == Y

QUESTION 12:

Rewrite the following if statement:

if ( !(car.price > 8000 ) )
  System.out.println("Affordable");
else
  System.out.println("Too Expensive!");

go to previous page   go to home page   go to next page