Program To Print Pascal’s Triangle in Java

pascal triangle pattern program in c
import java.util.*;  
class Main{
    public static void main(String ...a){
    int temp=1,i,j,k;
    Scanner sc= new Scanner(System.in);
    System.out.print("Enter number of rows: ");  
    int n= sc.nextInt();  
    for (i=0; i<n; i++) {
        for (k=1; k <= n-i; k++)
        {
            System.out.print(" ");
        }
        for (j=0; j<=i; j++) {
            if (j==0 || i==0)
                temp = 1;
            else
                temp=temp*(i-j+1)/j;
            System.out.print(" "+temp);
           }
        System.out.println("");
	    }
    }
} 
Pascal's Triangle Program in C

Leave a Comment