|
How to pass command line argument in a java program |
|
|
Any number of arguments can be passed to the java program through command line. While running the program any things written after the name of the class are the command line arguments. Arguments are delimited by the space.
This sample code prints all the command line arguments to the console.
public class CmdLnArgmntExp {
public static void main(String[] args) {
System.out.println("d");
for (int i = 0; i < args.length; i++)
System.out.println(args[i]);
}
}
|
Run the program as the follows.
Java CmdLnArgmntExp arg1 arg2 arg3 arg4
Output:
arg1
arg2
arg3
arg4
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.