Wednesday 7 October 2020

How to print Pyramid in Java

Pyramid using Java 


package in.jk;

public class Pyramid {
public static void main(String[] args) {
Pyramid pyramid = new Pyramid ();
pyramid .printPyramid();
}
    public void printPyramid(){
               int k=10;
   
for (int i = 0; i <=5; i++) {
for (int j = k-i; j >1; j--) {
System.out.print(" ");
}
for (int j = 0; j <=i; j++) {
System.out.print("J ");
}
System.out.println("");
 
}
    }
}


Output in Console ...

           
         J 
        J J 
       J J J 
      J J J J 
     J J J J J 
    J J J J J J 




1 comment:

  1. Thanks for sharing this informative post. It's really kind of content that I'm looking for a very helpful post by the way. If anyone looking for best Sas training institute in Delhi Contact Here-+91-9311002620 Or Visit our website https://www.htsindia.com/Courses/business-analytics/sas-training-institute-in-delhi

    ReplyDelete