Fill in the two blanks so that the nested if's make the correct choice.
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 first if
makes a
choice between its true branch and its false branch.
Its false branch is complicated, but that doesn't matter.
Each branch of an if
statement can be as complicated as needed.
Here is the fragment again,
with the first if's
true branch in blue
and its false branch in red:
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):" );
For example, if
(count+1)
is equal to 2,
the true branch is picked.
The variable suffix gets "nd",
and the false branch is completely skipped.