Cascade of || 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 ) || (  8 < 0 ) || ( 100 > 45 )
--------
  true

.... evaluation stops with the first true and the entire expression is true.

Cascade of || Operators

The || operator also has left to right associativity. In other words, it works like you expect. When an expression has several ||'s look for a true starting from the left and going toward the right. The first true stops the evaluation and causes the entire expression to be true. If every operand is false then every operand is evaluated and the entire expression is false.

When there are possible side effects it is important to understand that evaluation goes from left to right, as explained above. If there are no side effects (as in the expression used for the question) it doesn't really matter.

QUESTION 11:

What is the value of:

Math.sin( 0.5 ) >= Math.tan( 0.2 ) || 43.259 / 12.073 > 3.5 || ( 100 > 45 )