Java program to print pyramid pattern of numbers

Java program to print pyramid pattern of numbers. In the Java programming language, the pyramid number pattern is used. In Java, this program prints numbers pyramid form. Java programming language, print value beginning of the line print pattern.

public class Main
{ 
public static void main(String[] args) 
{ 
int n = 8; 
for (int i = 0; i < n; i++) 
{ 
int a = 1; 
System.out.printf("%" + (n - i) * 2 + "s", ""); 
for (int j = 0; j <= i; j++) 
{ 
System.out.printf("%4d", a); 
a = a * (i - j) / (j + 1); 
} 
System.out.println(); 
} 
} 
} 

Output:

                   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