Exercises

  1. 5.5 Describe the four basic elements of counter-controlled repetition.

  2. 5.6 Compare and contrast the while and for repetition statements.

  3. 5.7 Discuss a situation in which it would be more appropriate to use a dowhile statement than a while statement. Explain why.

  4. 5.8 Compare and contrast the break and continue statements.

  5. 5.9 Find and correct the error(s) in each of the following segments of code:

    1. For ( i = 100, i <= 1, i++ ) System.out.println( i );

    2. The following code should print whether integer value is odd or even:

      switch ( value % 2 ) { case 0: System.out.println( "Even integer" ); case 1: System.out.println( ...

Get Java How to Program (early objects), 9/e 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.