Another Demonstration

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:

Using the De Morgan Rule

!(A && B) is equivalent to !A || !B

the original expression

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

is equivalent to

boolean reject = !(speed > 2000) || !(memory > 512)

which is equivalent to

boolean reject = (speed <= 2000) || (memory <= 512)

Another Demonstration

Here is the other De Morgan rule:

!(A || B) is equivalent to !A && !B

This truth table shows why this rule is true.

A B (A || B) !(A || B) !A !B !A && !B
F F F T T T T
F T T F T F F
T F T F F T F
T T T F F F F

The fourth and the last column have the same truth values, which shows that the expressions at the top of those columns are equivalent.

QUESTION 14:

Rewrite the following fragment:

while ( !(input.equals( "quit" ) || (count > limit)) ) 
{
   . . . 
}