How to pass two values as parameter from command line and the get in it Java program?
The calculate the sum of two numbers using command line arguments in Java.
While calling Java program from command line you can pass two values a parameter.
For example if your class file name is AddNumbers then you can call like:
java AddNumbers 1 5
Then 1 and 5 will be passed as argument and you can get the value with following code:
int a = Integer.parseInt(args); int b = Integer.parseInt(args);
Now you can calculate the sume
int sum = a+b;
Check complete example code at Add Two Numbers in Java.