Thursday, 18 December 2014

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

// Exercise 4.3 - Question 5:

// Using a FOR loop.
// Write a program that reads a positive integer 'n' and then
// prints an "n-times-table" containing values up to 'n' * 'n'.
// For example, if the program reads the value 5, it should print
// only the following:
// 5 * 1 = 5
// 5 * 2 = 10
// 5 * 3 = 15
// 5 * 4 = 20
// 5 * 5 = 25

// Include 3 sets of outputs from this program

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

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

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

        c.println ("Enter a positive integer (> 0)");
        int integer = c.readInt ();

        for (int n = 1 ; n <= integer ; n++)
        {
            c.println (integer + " * " + n + " = " + integer * n);
        }

    } // main method
} // Exercise43D_Chapter4 class

No comments:

Post a Comment