Truth Tables and De Morgan's Rules
6. Truth Table
Answer:if ( !(speed > 2000 && memory > 512) ) System.out.println("Reject this computer"); else System.out.println("Acceptable computer");
Consider a computer with 2200 MHz speed and 750 Meg of memory. This computer is not rejected. Evaluation proceeds like this:
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.
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.
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");