Source code for SquaresWhileExample.java:

public class SquaresWhileExample
{
	public static void main(String args[])
	{
		// SquaresWhileExample
		int maximum = 10;
		int i = 0;
		while (i <= maximum)
		{
			int square = i * i;
			System.out.println(i + " squared is " + square);
			i++;
		}
	}
}

Output from SquaresWhileExample.java:

0 squared is 0 1 squared is 1 2 squared is 4 3 squared is 9 4 squared is 16 5 squared is 25 6 squared is 36 7 squared is 49 8 squared is 64 9 squared is 81 10 squared is 100

--- Output Ends ---

NOTE:

You are reading previously generated output. You are not currently running the SquaresWhileExample application at the momement. You need to compile and run the source code first.

To run this program:


Authors: Kevin Chu and Eric Brower
Copyright 2000 Prentice Hall PTR