Tuesday 11 September 2012

Java Practical - 1


    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

$
$ $
$ $ $
$ $ $ $

*/

Kindly Bookmark and Share it:

0 comments :

Post a Comment

Any Query ? any suggestion ? comment here

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT