This example demonstrate how value accepted from the command line. All argument need to placed at the command line at the time of executing your program.
This example demonstrate how value accepted from the command line. All argument need to placed at the command line at the time of executing your program.Description :
This example demonstrate how value accepted from the command line. All argument need to placed at the command line at the time of executing your program.
class CommandLineArgs{
public static void main(String args[]){
intl=args.length;
int sum=0;
for(int j=0;j<l ;j++)
{
sum=Integer.parseInt(args[j])+sum;
}
System.out.println("The Sum of All Elements entered at command line is : " + sum);
}
}
output
C:\commandLineArgument>
set path=C:\Program Files\Java\jdk1.6.0_11\bin
C:\commandLineArgument>javac CommandLineArgs.java
C:\commandLineArgument>java CommandLineArgs 12 5
The Sum of All Elements entered at command line is : 17