Write a program to draw Pyramids using nested for loops in java

We are providing here code for drawing 6 Pyramids with the help of inner or nested for loops in Java.

Code :
 public class PrintPyramid {  
      public static void main(String args[])  
      {  
           //Pyramid One  
           for(int i=1;i<=5;i++)  
           {                 
                for(int j=1;j<=i;j++)  
                     {  
                          System.out.print("@ ");  
                     }  
                System.out.println();  
           }  
           //Pyramid Two  
           for(int i=1;i<=5;i++)  
           {                 
                for(int j=1;j<=5-i;j++)  
                     {  
                          System.out.print("# ");  
                     }  
                System.out.println();  
           }  
           //Pyramid Three  
           for(int i=1;i<=5;i++)  
           {                 
                for(int j=1;j<=5-i;j++)  
                     {  
                          System.out.print(j);  
                     }  
                System.out.println();  
           }  
           //Pyramid Four  
           for(int i=1;i<=5;i++)  
           {                 
                for(int j=1;j<=i;j++)  
                     {  
                          System.out.print(i);  
                     }  
                System.out.println();  
           }  
           //Pyramid Five  
           for(int i=1;i<=5;i++)  
           {                 
                for(int j=1;j<=5-i;j++)  
                     {  
                          System.out.print(" ");  
                     }  
                for(int k=1;k<=i;k++)  
                {  
                     System.out.print("% ");  
                }  
                System.out.println();  
           }  
           //Pyramid Six  
           for(int i=1;i<=5;i++)  
           {                 
                for(int j=1;j<=5-i;j++)  
                     {  
                          System.out.print(" ");  
                     }  
                for(int k=1;k<=i;k++)  
                {  
                     System.out.print("$ ");  
                }  
                for(int l=1;l<i;l++)  
                {  
                     System.out.print("$ ");  
                }  
                System.out.println();  
           }  
      }  
 }  
Output :

No comments: