Thursday, 18 December 2014

// The "Example1A_Chapter4" class.
// (from the Carter book)

// Example 1A shows how WHILE loops work in Java.
// This program is called "PrintSquares" and prints
// out the input values and their squares as long as
// the input values are not 0.

import java.awt.*;
import hsa.Console;

public class Example1A_Chapter4
{
    static Console c;           // The output console

    public static void main (String[] args)
    {
        c = new Console ();

        c.println ("Give an integer, 0 to stop");
        int value = c.readInt ();

        while (value != 0)
        {
            c.println (value + " " + value * value);
            c.println ("Next integer, please (0 to stop)");
            value = c.readInt ();
        }

    } // main method
} // Example1A_Chapter4 class

No comments:

Post a Comment