Two AND Operators

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   hear noise   go to next page

Answer:

(4 < 8 ) && (12 <= 40 ) && (50 > 1)

is true

Two AND Operators

An expression with two && operators works like you expect. But let us look at the situation in detail. When the && operator is used twice in an expression, group the first && and its operands together like this:

  (4 < 8 ) && (12 <= 40 )  && (50 > 1)

     is equivalent to:

( (4 < 8 ) && (12 <= 40 )) && (50 > 1)

Now evaluate that first group. The result is a true or false that is used with the next && operator:

(          true          ) && (50 > 1)

The effect of this is that for the entire expression to be true, every operand must be true. One or more false values cause the entire expression to be false.

Short-circuit evaluation is still going on, so the first false value stops evaluation and causes the entire expression to be false.

QUESTION 9:

What is the value of:

(4 < 8 ) && (  8 < 0 ) && ( 100 > 45 )