O'Reilly logo

Java™ How to Program, Seventh Edition by P. J. Deitel - Deitel & Associates, Inc., H. M. Deitel - Deitel & Associates, Inc.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercises

5.5Describe the four basic elements of counter-controlled repetition.
5.6Compare and contrast the while and for repetition statements.
5.7Discuss a situation in which it would be more appropriate to use a do...while statement than a while statement. Explain why.
5.8Compare and contrast the break and continue statements.
5.9Find 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( "Odd integer" );
    }
  3. The following code should output the odd integers from 19 to 1:

    for ( i = 19; i >= 1; i += 2 ) System.out.println( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required