Thursday, 4 July 2013

command line arguments program

/*command line argument*/


class cmd

{

 public static void main(String[] args)

 {

  for(int i=0;i<args.length;i++)

  {

  System.out.println("value="+args[i]);

 }

 }

}

note:
for compiling command line arguments 
you have to pass arguments next to class file name
i.e, here my class name is cmd
for creating class file
-->javac cmd.java
for running class file(your java program)
-->java cmd eminem is the best rapper

Output -->
1stvalue=eminem
2ndvalue=is
3rdvalue=the
4thvalue=best
5thvalue=rapper

In this program the first string is given 0 value 
In output we are giving 5 strings so it assigns 0-4 values

No comments:

Post a Comment