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:
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:
No comments:
Post a Comment