Program Definition 1 ::
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.
class P1
{
public static void main(String args[])
{
System.out.println(" Program 1 \n\n");
for(int i = 0 ; i < 5 ; i++ )
{
for( int j = 0 ; j < i ; j++ )
{
System.out.print(" " + args[0]);
}
System.out.println();
}
}
}
/* OUTPUT
D:\JAVA>javac P1.java
D:\JAVA>java P1 $
Program 1
$
$ $
$ $ $
$ $ $ $
{
public static void main(String args[])
{
System.out.println(" Program 1 \n\n");
for(int i = 0 ; i < 5 ; i++ )
{
for( int j = 0 ; j < i ; j++ )
{
System.out.print(" " + args[0]);
}
System.out.println();
}
}
}
/* OUTPUT
D:\JAVA>javac P1.java
D:\JAVA>java P1 $
Program 1
$
$ $
$ $ $
$ $ $ $
*/
0 comments :