//  File:  TwoDArrays.java  -  Simple 2D Arrays:
//                             Rectangular and Triangular

public class TwoDArrays {

    // This method displays any 2D array
    public static void printArray(char[][] cArray) {
        for (int i = 0; i < cArray.length; i++) {
            for (int j = 0; j < cArray[i].length; j++)
                System.out.print(" " + cArray[i][j]);
            System.out.println();
        }
        System.out.println();
    }

    public static void main(String args[]) {
        System.out.println("Simple Rectangular 2D Array");
        System.out.println();
        
        char[][] c2D = new char[3][5];
        char ch = 'A';
        // Load up the array with alphabetics
        for (int i = 0; i < c2D.length; i++)
            for (int j = 0; j < c2D[i].length; j++)
                c2D[i][j] = ch++;

        printArray(c2D);


        System.out.println("Simple Triangular 2D Array");
        System.out.println();

        char[][] cTri = new char[5][];
        // Load up the array with alphabetics
        ch = 'A';
        for (int i = 0; i < cTri.length; i++) {
            cTri[i] = new char[i+1];
            for (int j = 0; j < cTri[i].length; j++)
                cTri[i][j] = ch++;
        }

        printArray(cTri);
    }
}

/* ..... Output from the above program .....

Simple Rectangular 2D Array

 A B C D E
 F G H I J
 K L M N O

Simple Triangular 2D Array

 A
 B C
 D E F
 G H I J
 K L M N O
 
..... End of Output ..... */
