Wednesday, 3 December 2014

// The "DoWhileLoop1" class.  Page 140.  (from the Carter book)

// Example 1. This program fragment forces a user to supply
// a value that lies in the range of 1 to 10.  If outside this
// range, the do-while loop will not run and a message to show
// the end of the program appears.

public class DoWhileLoop1
{
    public static void main (String[] args)
    {
        int value;
        do
        {
            System.out.println ("Enter an integer from 1 to 10 only -- ");
            System.out.println ("End with an invalid value (0, <0, or >10)");
            value = In.getInt ();
        }
        while (value >= 1 && value <= 10);
        System.out.println ("");
        System.out.println ("The 'DoWhileLoop1' program has now terminated");

    } // main method
} // DoWhileLoop1 class

No comments:

Post a Comment