Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (2.6k points)
I am getting error to print pyramid pattern in java. Can someone help me?

1 Answer

0 votes
by (7.2k points)

To print pyramid pattern in JAVA, use this code...

public static void main(String[] args) {

 

     for(int k=0;k<5;k++) {

         for(int k1=0;k1<5-i;k1++) {

             System.out.print(" ");

         }

        for(int k2=0;k2<=k;k2++) {

            System.out.print("* ");

        }

        System.out.println();  

    }

 

}

Output:

 

     * 

    * * 

   * * * 

  * * * * 

* * * * *

Related questions

0 votes
1 answer
0 votes
1 answer
asked Feb 18, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer
asked Jan 12, 2021 in Python by ashely (50.2k points)
0 votes
1 answer
asked Feb 25, 2021 in Java by rahulnayar01123 (6.1k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...