Chapter 17 The Dual-Alternative Decision Structure

17.1 The Dual-Alternative Decision Structure

In contrast to the single-alternative decision structure, this type of decision control structure includes a statement or block of statements on both paths.

Image

If Boolean_Expression evaluates to true, the statement or block of statements 1 is executed; otherwise, the statement or block of statements 2 is executed.

The general form of the Java statement is

if (Boolean_Expression) {
A statement or block of statements 1
}
else {
A statement or block of statements 2
}

In the next example, the message “You are an adult” is displayed when the user enters a ...

Get Java and Algorithmic Thinking for the Complete Beginner 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.