Friday, August 1, 2014

Taking in Command Line Arguments
In Java, the program can be written to accept command-line-arguments.
 Example Code: command-line arguments

/* This Java application illustrates the use of Java command-line arguments. */
public class CmdLineArgsApp {
public static void main(String[] args){ //main method
System.out.println(”First argument ” + args[0]);
System.out.println(”Second argument ” + args[1]);
}//end main
}//End class. 

 Example Code: Passing any number of arguments
In java, array knows their size by using the length property. By using, length property we can determine how many arguments were passed. The following code example can accept any number of arguments
/* This Java application illustrates the use of Java
command-line arguments. */
public class AnyArgsApp {
public static void main(String[] args){ //main method
for(int i=0; i < args.length; i++)
System.out.println(“Argument:” + i + “value” +args[i]);
}//end main
}//End class.

   Output
               C:\java AnyArgsApp i can pass any number of arguments
Argument:0 value i Argument:1 value can Argument:2 value pass Argument:3 value any Argument:4 value number Argument:5 value of Argument:6 value arguments

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...