Open In App

Java Program to Add Two Numbers

Last Updated : 25 Dec, 2023
Comments
Improve
Suggest changes
10 Likes
Like
Report

Given two integers num1 and num2, the task is to find the sum of the given two numbers in Java.

Example of Addition of Two Numbers

Input: A = 5, B = 6
Output: sum = 11

Input: A = 4, B = 11 
Output: sum = 15  

Program to Add Two Numbers in Java

Below is the implementation of adding two Numbers are mentioned below:


Output
77

Using Bit Manipulation for Addition of Two Numbers in Java

Bitwise Operators are the operators that can directly operate on the bit values.

Below is the implementation of the above method:


Output
77

Sum of Three Numbers in Java

Sum of Three Numbers in itself is like Adding Two Numbers Two Times.

Example:


Output
Method 1: Sum a+b+c = 6
Method 2: Sum a+b+c = 6

Sum of N Numbers in Java

Sum of N Numbers in Java can be done using the Steps mentioned below:

  • Take input of N Numbers
  • Use Loop to Add the N Numbers in Java(Iterate and Sum simultaneously)
  • Print the Sum calculated.

Below is the implementation of the above method:

Output:

Enter the Number of elements: 4
10
20
30
40
Sum of Input Numbers : 100

Miscellanous of Addition of Two Numbers in Java

These are the two Methods for Adding Two Numbers which are bit complex to implement as compared to the methods mentioned above.

1. Sum of Two Numbers Using Command Line Arguments in Java

Output

Adding_Two_Numbers_Using_Command_Line

2. Program to Add Two BigIntegers in Java

BigIntegers are the numbers that exceed the limit of Integers So we created another class called BigInteger.

Below is the implementation of the Addition of Two BigIntegers:


Output
Sum of Two BigIntegers: 15966888634697288357207200089

Article Tags :
Practice Tags :

Similar Reads