command line arguments in java, Java Program to add two no. given by user from command prompt

Java Program To Add Two Numbers Using Command line arguments in java

Now, In this Program to Add Two Numbers using Command line arguments in java, you should have the knowledge of following topics:

1.Accepting Inputs Through Command Line Arguments In Java
2.Variables and Data Types
3.Operators

 

class AddNos
{
	public static void main(String [] args)
{
		int num1,num2,sum;
		num1=Integer.parseInt(args[0]);
		num2=Integer.parseInt(args[1]);

		sum=num1+num2;

		System.out.println("first no="+num1);
		System.out.println("second no="+num2);
		System.out.println("Sum of "+num1 +" & "+num2 +" is: "+sum);
	}
}

Output:
Java-Add 2 No.s Using Command Line

Most Importantly as mentioned above Java uses all the mathematics operation therefore by Changing (+) operator, we can subtract (-), multiply (*), divide (/), floor divide (//) or find the remainder (%) of two numbers.

Related Program

1.Java Program to find the area of Triangle
2.Java Program to Solve Quadratic Equation
3.Java Program to Generate a Random Number

Ask your questions and clarify your/others doubts by commenting. Java Documentation[/vc_column_text][/vc_column][/vc_row]

Program using Command line arguments in java