Home Tutorial Java Core Commandline Passing argument at command line using Core Java

 
 

Passing argument at command line using Core Java
Posted on: March 15, 2010 at 12:00 AM
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

Related Tags for Passing argument at command line using Core Java:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.