Java Program to Add Two Numbers-Initializing Method

To properly understand a Java Program to Add Two Numbers, you should have the knowledge of following Java programming topics:

 

1.Input, Output, and Import
2.Variables and Data Types
3.Operators

In the following program, we have used the arithmetic addition operator i.e (+) to adds two numbers.

#Java Program to Add two numbers
class Add2nos{
        public static void main(String args []){

                double num1 = 2.5, num2 = 4.3, sum;
                sum = num1 + num2;

                System.out.println("Sum of "+num1 +" and " +num2 +"is: "+sum);
   }
}

Output

Sum of 2.5 and 4.3 is: 6.8

 

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

Java Program to Add Two Numbers

Shubham Tripathi

Java Developer (Full Stack) , Passionate about creating impact on scale | striving for a continuous improvement | learning entire gamut of Computer technologies | Raising my technical skills & trying to become a better person everyday |

    See all posts by admin