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

A single single taxpayer with an income of $24000 up to $58150 (inclusive) falls into the 28% "tax bracket."

Answer:

// check that the income is within range for the 28% bracket
if ( income >=24000 && income <= 58150  )
  System.out.println("In the 28% bracket." );
else
  System.out.println("Time for an audit!" );

Complete Boolean Expressions

AND combines the results of two relational expressions, like this:

income >= 24000  &&  income <= 58150
-------------       ---------------
relational            relational
expression            expression

Each relational expression must be complete. The following is a MISTAKE:

income >= 24000  &&      <= 58150
-------------        ---------------
relational             not a complete
expression             relational
                       expression

This is INCORRECT because the characters that follow && do not form a complete relational expression. The Java compiler would not accept this.

QUESTION 12:

Here is an incorrect boolean expression that is intended to test if a person's age is between 21 and 35.

age >= 21 && <= 35

Fix the boolean expression.