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

Answer:


Different Suffixes

The first integer is prompted for outside of the loop. Inside the loop body, it would be nice to use the following prompts:

Enter the 2nd integer (enter 0 to quit):
Enter the 3rd integer (enter 0 to quit):
Enter the 4th integer (enter 0 to quit):
Enter the 5th integer (enter 0 to quit):
Enter the 6th integer (enter 0 to quit):

.... and so on ....

Enter the 20th integer (enter 0 to quit):
Enter the 21th integer (enter 0 to quit):

The prompt shows poor grammar for integers 21, 22, 23, 31, 32, 33 and so on. Let us regard this as acceptable for now. (If you want, improve the program so it is correct for all counts. The remainder operator % will be useful for this.)

The output statement is now:

System.out.println( "Enter the " + 
  (count+1) + suffix + " integer (enter 0 to quit):" );

The variable suffix will be a reference to one of the Strings: "nd", "rd", or "th".


QUESTION 8:

A choice must be made from among three things. Can a single if-else statement do this?