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

Answer:

if (  !(speed > 2000 && memory > 512)  )
  System.out.println("Reject this computer");
else
  System.out.println("Acceptable computer");

Truth Table

Consider a computer with 2200 MHz speed and 750 Meg of memory. This computer is not rejected. Evaluation proceeds like this:

Boolean Expression

A truth table is another way to analyze the expression. The first two columns are filled with all possible truth values of the relational expressions. The remaining cells show how these truth values are combined.

If speed is 2200 and memory is 750 the the fourth row of the table is selected. The last column shows that this computer is not rejected. All computers are rejected except for those that meet both requirements, corresponding to the last row of the table.


speed > 2000 memory > 512 speed > 2000 && memory > 512 Reject Computer if

!(speed > 2000 && memory > 512)
F F
F T
T F
T T

QUESTION 6:

Does the following program fragment do the same thing as the original fragment?

boolean reject = !(speed > 2000 && memory > 512);

if (  reject  )
  System.out.println("Reject this computer");
else
  System.out.println("Acceptable computer");

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