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

Answer:

Enter your age
11
Child rate
Enjoy the show

Boolean Expressions

We need to look at the condition part of the if statement. Usually this is a boolean expression. Recall that an expression is is a combination of literals, operators, variable names, and parentheses used to calculate a value.

A boolean expression is an expression that evaluates to true or false.

Boolean expressions often compare numbers. A relational operator says how the numbers are compared.

Relational Operators
OperatorMeaning
A == B is A equal to B ?
A < B is A less than B ?
A <= B is A less than or equal to B ?
A > B is A Greater than B ?
A >= B is A Greater than or equal to B ?
A != B is A not equal to B ?

Here are some annoying details (that will be really annoying later on if you forget about them):

  • The operator for "equal" is   ==   (two equal signs in a row). In your web browser it may be hard to see that there are two equal signs.
  • The operator for "not equal" is   !=   (exclaimation point equal sign).

It is easy to forget these two details, and easy to overlook these details in a program. You might spend hours debugging a program because a   =   was used where a   ==   belongs.

QUESTION 13:

Fill in the blanks in the following chart:
Expression ValueExpression Value
25 == 25 25 != 25
25 <= 25 25 > 25
25 >= 25 25 = 25
-5 < 7 -305 <= 97