For each of the following possible values of (count+1),
which branch of the first if will be executed?
Answer:
- 2 true branch
- 3 false branch
- 4 false branch
- 5 false branch
Nested if Statement
When (count+1) is equal to 3,
the false branch
is executed.
if ( count+1 == 2 ) suffix = "nd" else if ( count+1 == 3 ) suffix = "rd"; else suffix = "th"; System.out.println( "Enter the " + (count+1) + suffix + " integer (enter 0 to quit):" );
The false branch consists of an if statement.
When this nested if statement is executed,
its true branch will execute,
selecting the String "rd" for suffix.
The next statement to execute is the println.
QUESTION 11:
What suffix is chosen if (count+1) is equal to 5?