Java Program to print pyramid pattern using command line arguments

Write a simple java application to print a pyramid with 5 lines. The first line has one character,
2nd line has two characters and so on. The character to be used in the pyramid is taken as a
command line argument.

Program:

public class pyramid

   public static void main(String args[])
   {

    int i, j, k;
    for(i=1; i<6; i++)
    {
        for(k=6; k>i; k--)
        {
            System.out.print(" ");
        }
        for(j=1; j<=i; j++)
        {
            System.out.print(args[0]+" ");
        }
        System.out.print("\n");
    }
   }
}


Output:

Comments

Popular Posts