Blog

Java Program to Add Two Numbers

Java / Java Programs

Java Program to Add Two Numbers

[vc_row][vc_column][vc_column_text]

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[/vc_column_text][/vc_column][/vc_row]

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare