4-8 UserSquares

posted Feb 23, 2014, 1:18 PM by Dlovan ismail   [ updated Feb 23, 2014, 1:18 PM by Karwan Jacksi ]
//This program demonstrates a user controlled for loop.

package usersquares;
import java.util.Scanner; // Needed for the Scanner class

public class UserSquares
{
    public static void main(String[] args)
    {
            int number;       // Loop control variable
            int maxValue;  // Maximum value to display

            System.out.println("I will display a table of numbers and their squares.");

            // Create a Scanner object for keyboard input.
            Scanner keyboard = new Scanner(System.in);

            // Get the maximum value to display.
            System.out.print("How high should I go? " );
            maxValue = keyboard.nextInt();

            // Display the table.
            System.out.println("Number Number Squared");
            System.out.println("-----------------------");

            for (number = 1; number <= maxValue; number++)
            {
                System.out.println(number+"\t\t"+number*number);
            }
            
    }  
}

ċ
UserSquares.java
(1k)
Karwan Jacksi,
Feb 23, 2014, 1:18 PM
Comments