Pyramid pattern in java.

 ■》 code link -> click 👇👇👇

                         Method-1


https://www.programiz.com/online-compiler/3wQNCxKuLTcCi

                         Method -2


■》Program  to print pyramid  pattern using         for loop in java.

import java.util.*;

public class pyramid {

    public static void main(String[] args){

        Scanner sc=new Scanner(System.in);

        System.out.println("enter the 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<=2*i-1; j++){

                System.out.print("*");

            }

            System.out.println();

        }

    }

}

■》Output->

enter the no. of rows=5

       *

     ***

    *****

  *******

*********

            




Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.