Truth Table

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

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 the possible truth values of the relational expressions. The remaining cells show how these truth values are combined.

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

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.

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");