Program to Add Two Numbers in Java

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

Java




// Java Program to implement
// Direct Addition to Add two Numbers
import java.io.*;
 
// Driver Class
class GFG {
    public static int sum(int num1, int num2)
    {
        return num1+num2;
    }
     
      // main function
    public static void main(String[] args)
    {
        GFG ob = new GFG();
        int res = ob.sum(28, 49);
        System.out.println(res);
    }
}


Output

77

Java Program to Add Two Numbers

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  

Similar Reads

Program to Add Two Numbers in Java

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

Using Bit Manipulation for Addition of Two Numbers in Java

...

Sum of Three Numbers in Java

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

Sum of N Numbers in Java

...

Miscellanous of Addition of Two Numbers in Java

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