2.8 Decision Making: Equality and Relational Operators
A condition is an expression that can be true
or false
. This section introduces Java’s if
selection statement, which 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’ll 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 ...
Get Java How to Program (early objects), 9/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.