Monday, 29 July 2013

How To Use Command Line Arguments In Java

Command line arguments is the way to pass values to the program at the time of execution of the program.

Here is the program:

class Add
{
public static void main(String args[])
{
int num1,num2,res;
num1 = Integer.parseInt(args[0]);
num2 = Integer.parseInt(args[1]);
res = num1+num2;
System.out.println("sum is"+res);
}
}

In this program some methods are used that are:


1.Integer.parseInt :-Change the user input to integer because the value we have entered is in integer but it will be interpreted as a String.

Output of Program:

Command line arguments


Like the Post? Do share with your Friends.

No comments:

Post a Comment

IconIconIconFollow Me on Pinterest

Blogger news

Blogroll

What's Hot