How to Print Triangle Pyramid using character “*”

public class TrianglePyramid{
     public static void main(String args[]){
        int a, b, c, row = 5;
        for (a=0; a<row; a++)
        {
            for (b=row-a; b>1; b--)
            {
                System.out.print(" ");
            }
            for (b=0; b<=a; b++)
            {
                System.out.print("*");
            }
            for(c=0; c<a; c++)
            {
                System.out.print("*");
            }
            System.out.println();
        }
        
     }
}

Output: –

    *
   ***
  *****
 *******
*********




Leave a Reply

Your email address will not be published. Required fields are marked *