Boolean Expression in a Loop's Test

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.

Answer:

The test part of the loop can use the OR operator to allow several choices.

Boolean Expression in a Loop's Test

The test part of a loop (any of the three varieties) is a boolean expression. We want a boolean expression that evaluates to true if the user enters:

  • yes
  • YES
  • Y
  • y

and evaluates to false for anything else. Here is a near-complete expression:

( chars.equals( "yes" )   chars.equals( "YES" )   
  chars.equals( "y" )     chars.equals( "Y" )  )

QUESTION 8:

Fill in the blanks.