Boolean Expressions with OR

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

Say that you enter 56000 for cash and 0 for credit.

Answer:

               
cash   >= 25000   true   

credit >= 25000   false   

cash  >= 25000 || credit >= 25000   true   

Boolean Expressions with OR

The OR operator is used in a boolean expression to check that there is at least one true. If both sides are true, the entire expression is true. If just one side is true, the entire expression is true. If both sides are false, the entire expression is false. The OR operator is a logical operator because it combines two true/false values into a single true/false value.

or operator

Here is how || works:

  • true  || true  = true
  • false || true  = true
  • true  || false = true
  • false || false = false

OR checks that at least one requirement is met. This type of OR is called an inclusive OR because its value is true for one or two true values.

Often in English word "or" is used when any number of conditions can be true. For example, in this sentence

Successful job seekers must have experience or training.

Sometimes the English word "or" is used when only one condition can be true at a time. For example, in this sentence

It will rain today or it will be clear.

only one condition, "rain" or "clear", can be true. This is called an exclusive OR. In programming, "or" means inclusive or.

QUESTION 18:

Here is a boolean expression:

34 > 2 || 5 == 7

Is this expression true or false ?