Source code for SquaresForLoopExample.java:

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

Output from SquaresForLoopExample.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 SquaresForLoopExample 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