public class CommandLineArguments
{
public static void main(String[] args)
{
System.out.println("Total number of Command Line Arguments: "+args.length);
System.out.println("Command Line Arguments:");
for(int i=0;i<args.length;i++)
System.out.println(args[i]);
}
}
Type the above program in Notepad and Save it as CommandLineArguments.java
Compile like this:
javac CommandLineArguments.java
Run like this:
java CommandLineArguments Arguments
For example:
java CommandLineArguments Hello World
output:
Total number of Command Line Arguments: 2
Command Line Arguments:
Hello
World
If you run like this:
java CommandLineArguments
output:
Total number of Command Line Arguments: 0
Command Line Arguments:
Note: Each argument in command line arguments is seperated by a space
Compile like this:
javac CommandLineArguments.java
Run like this:
java CommandLineArguments Arguments
For example:
java CommandLineArguments Hello World
output:
Total number of Command Line Arguments: 2
Command Line Arguments:
Hello
World
If you run like this:
java CommandLineArguments
output:
Total number of Command Line Arguments: 0
Command Line Arguments:
Note: Each argument in command line arguments is seperated by a space
No comments:
Post a Comment