2.8. Decision Making: Equality and Relational Operators

A condition is an expression that can be either true or false. This section introduces Java’s if statement that allows a program to make a decision based on a condition’s value. For example, the condition “grade is greater than or equal to 60” determines whether a student passed a test. If the condition in an if statement is true, the body of the if statement executes. If the condition is false, the body does not execute. We will see an example shortly.

Conditions in if statements can be formed by using the equality operators (== and !=) and relational operators(>, <, >= and <=) summarized in Fig. 2.14. Both equality operators have the same level of precedence, which is lower than that ...

Get Java™ How to Program, Seventh Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.