A good answer might be:

if (  !(speed > 400 && memory > 32)  )
  System.out.println("Reject this computer");
else
  System.out.println("Acceptable computer");
(It would probably be better in this simple case to reverse the bodies of the true-branch and the false-branch. But say that there were other considerations that made this undesirable.)

Precidence of NOT

It is important to put parentheses around the entire expression who's true/false value you wish to reverse. Evaluation of the example proceeds like this:

! (  speed > 400   &&   memory > 32 )
     ------+------      -------+----

! (         T      &&          T   )

! (                 T              )

                   !T

                    F

The NOT operator has high precidence, so it will be done first (before arithmetic and relational operators) unless you use parentheses. For example, without the parentheses in the above expression, this would happen:

!speed > 400   &&   memory > 32
--+---  
illegal: can't use ! on an arithmetic variable

Since ! has high precidence, the compiler will try to apply it to speed, which won't work.

Sometimes using NOT can lead to confusing program errors. It is usually best to say directly what you mean and arrange the program logic so that this works.

QUESTION 22:

What is the true/false value of the following:

!( true || false )
Click Here after you have answered the question