Share on Google+Share on Google+

Passing argument at command line using Core Java

Advertisement
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.

How to pass Command Line Argument using Core Java

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

Advertisements

Advertisement

Posted on: March 15, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.