Section 4.6 if...else Double-Selection Statement

• The if single-selection statement performs an indicated action only when the condition is true.

• The if...else double-selection (p. 105) statement performs one action when the condition is true and another action when the condition is false.

• A program can test multiple cases with nested if...else statements (p. 107).

• The conditional operator (p. 110; ?:) is Java’s only ternary operator—it takes three operands. Together, the operands and the ?: symbol form a conditional expression (p. 110).

• The Java compiler associates an else with the immediately preceding if unless told to do otherwise by the placement of braces.

• The if statement expects one statement in its body. To include several ...

Get Java™ How To Program (Early Objects), Tenth Edition 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.