go to previous page   go to home page   go to next page hear noise highlighting

For each of the following possible values of (count+1), which branch of the first if will be executed?

Answer:


Nested if Statement

When (count+1) is equal to 3, the false branch is executed. The false branch consists of an if statement.

When this nested if statement is executed, its true branch will execute, selecting "rd" for suffix. The next statement to execute is the println.


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):" );

QUESTION 11:

What suffix is chosen if (count+1) is equal to 5?


go to previous page   go to home page   go to next page