Equivalent Boolean Expressions

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:

speed > 2000 (speed <= 2000)!(speed <= 2000)
F T F
T F T

Equivalent Boolean Expressions

The original program fragment used this boolean expression

!(speed > 2000 && memory > 512)

which is explained in the following truth table (repeated from a previous page):

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

An equivalent program fragment used this boolean expression

speed <= 2000 || memory <= 512

which is explained in the following truth table:

speed > 2000 memory > 512 speed <= 2000 memory <= 512 speed <= 2000 || memory <= 512
F F T T T
F T T F T
T F F T T
T T F F F

Each table has the same first two columns. The true/false values in the last column of each table are the same, which shows that the two boolean expressions are equivalent. One expression can be used in place of the other in a program.

QUESTION 9:

Is there only one correct way to write an if statement in a program?