/**
 * Class TriangleArray
 * Just to illustrate the point that multidimensional arrays are
 * simply arrays of arrays and that 2-dimensional arrays are
 * not neccesarily rectangular matrices.
 *
 * $Revision: 1.2 $
 * $Date: 2003/07/20 02:14:24 $
 *
 * @author Serguei Mokhov, mokhov@cs.concordia.ca
 * @since Summer 2002 
 */
public class TriangleArray
{
	public static void main(String[] argv)
	{
		// At this point it's an uni-dim. array of 7 float[] elements
		float aTriangle[][] = new float[7][];

		// For everyone of those 7
		for(int i = 0; i < aTriangle.length; i++)
		{
			// Allocate a new object array
			// of size [1..aTriangle.length]
			aTriangle[i] = new float[i + 1];

			/* And initialize them to some values
			 * The values are artificial.
			 * The sum "(float)(i + j)" can be replaced by just "i + j";
			 * It's there to show similarity with casts to that if C++.
			 */
			for(int j = 0; j < i + 1; j++)
				aTriangle[i][j] = (float)(i + j);
		}

		/* Print the array out.
		 * print() outputs a string, and println() does so
		 * too, but append EOL (\n) at the end of line.
		 */
		for(int i = 0; i < aTriangle.length; i++)
		{
			for(int j = 0; j < aTriangle[i].length; j++)
				System.out.print("[" + aTriangle[i][j] + "]");

			System.out.println();
		}
	}
}

// EOF

