Pyramid with row numbers pattern in java.

■》Code link -> click πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡


■  Program->

import java.util.*;
public class pyramidwithnumber {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("enter no. of rows=");
        int n=sc.nextInt();
        for(int i=1; i<=n; i++){
            for(int j=1; j<=n-i; j++){
                System.out.print(" ");
            }
            for(int j=1; j<=i; j++){
                System.out.print(i+" ");
            }
            System.out.println();
        }
    }
}

■》 Output->

enter no. of rows=5
 
       1
     2 2
    3 3 3
  4 4 4 4 
 5 5 5 5 5 




    

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.