import java.io.*;

public class PascalTriangle {

    private int data[][];

    /** Create a Pascal's triangle to specified depth. */
    public PascalTriangle(int rows) {
        data = new int[rows][];
        for (int row = 0; row < rows; row++) {
            data[row] = new int[row + 1];
            if (row == 0)
                data[row][0] = 1;
            else
                for (int col = 0; col <= row; col++) {
                    data[row][col] = 0;
                    // if not on right edge, add node up and right
                    if (col < row)
                        data[row][col] += data[row - 1][col];
                    // if not on left edge, add node up and left
                    if (col > 0)
                        data[row][col] += data[row - 1][col - 1];
                }
        }
    }

    /** Print this Pascal's triangle to given stream. */
    public void print(PrintStream ps) {        
        for (int i = 0; i < data.length; i++) {
            int[] row = data[i];
            for (int j = 0; j < row.length; j++)
                ps.print(row[j] + " ");
            ps.println();
        }
    }

    /** Create a Pascal's triangle of depth 12 and print it. */
    public static void main(String[] args)
    {
        PascalTriangle pt = new PascalTriangle(12);
        pt.print(System.out);
    }
}
