.
Previous Next

Write a Java program to print the numbers in pyramid format?

/*Q. Write a Java Program to Print the Numbers in Pyramid format?*/
public class PyramidNumbers {
     public static void main(String[] args) {
           int rows = 11; /* give input here*/        
           for (int i = 1; i <= rows; i++) {
                int number = 1;
                System.out.format("%"+ (rows-i+1)*2+"s","");
                for (int j = 1; j <= i; j++) {
                      System.out.format("%4d",number++);   
                }
                System.out.println();
           }
     }
 }
Previous Next