Answers to Self-Review Exercises

5.1
  1. for, while.

  2. after.

  3. switch.

  4. continue.

  5. && (conditional AND).

  6. false.

  7. static.

5.2
  1. False. The default case is optional. If no default action is needed, then there is no need for a default case.

  2. False. The break statement is used to exit the switch statement. The break statement is not required for the last case in a switch statement.

  3. False. Both of the relational expressions must be true for the entire expression to be true when using the && operator.

  4. True.

  5. True.

  6. False. The switch statement does not provide a mechanism for testing ranges of values, so every value that must be tested should be listed in a separate case label.

  7. True.

5.3
  1. sum = 0;
    for ( count = 1; <= 99; count += 2 )
       sum += count;
  2. double result = Math.pow( 2.5 ...

Get Java™ How to Program, Seventh Edition 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.