Wednesday, 3 December 2014

// The "WhileLoop1a" class (or, the "PrintSquares" class).
// Page 135. (from the Carter book)

// Example 1a.  The following program reads integers and
// prints them along with their squares.  It continues to
// read and print them until the user provides a value of zero
// (the sentinel or terminating value).

public class WhileLoop1
{
    public static void main (String[] args)
    {
        System.out.println ("Please enter any positive integer (0 to end)");
        int value = In.getInt ();
        while (value != 0)
        {
            System.out.println (value + "\t" + value * value);
            System.out.println ("(0 to end)");
            value = In.getInt ();
        } // end of while loop

    } // main method
} // WhileLoop1 class

No comments:

Post a Comment