Pascal Triangle



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Scanner;

public class PasclasTriangleProgram {

 public static void main(String args[]) {

  Scanner in = new Scanner(System.in);
  System.out.println("Enter number of rows ");

  int rows = in.nextInt();

  for (int i = 0; i < rows; i++) {

   int number = 1;

   System.out.format("%" + (rows - i) * 2 + "s", "");

   for (int j = 0; j <= i; j++) {

    System.out.format("%4d", number);

    number = number * (i - j) / (j + 1);

   }

   System.out.println();

  }

 }
}