AP Computer Science --- Haas --- Pascal

Objective: Write a class which draws Pascal triangles.

You are probably already familiar with Pascal's Triangle pictured below.

At the top of Pascal's Triangle is the number 1, which makes up the zeroth row. The first row (1 & 1) contains two 1's, both formed by adding the two numbers above them to the left and the right, in this case 1 and 0 (all numbers outside the Triangle are 0's). Do the same to create the 2nd row: 0+1=1; 1+1=2; 1+0=1. And the third: 0+1=1; 1+2=3; 2+1=3; 1+0=1. In this way, the rows of the triangle go on infinitly.

A number in the triangle can also be found by the equation (r!)/(n!*(r-n)!) Where r is the row and n is the element in that row.

IMPORTANT: By definition 0! = 1.

Your triangle can be "left justified" see below:


1  
1  1  
1  2  1  
1  3  3  1  
1  4  6  4  1  
1  5  10  10  5  1  
1  6  15  20  15  6  1  
1  7  21  35  35  21  7  1 

Create a class Pascal with 3 methods:



/** 
 * >>>>>> TESTER for class Pascal --- This code is complete <<<<<<
 */
public class PascalTester
{
   public static void main(String args[])
   {
       Pascal Haas = new Pascal();

       Haas.drawTriangle(5); // draws a 5 row Pascal triangle
       Haas.drawTriangle(3); // draws a 3 row Pascal triangle
       Haas.drawTriangle(8); // draws an 8 row Pascal triangle
    }
}