In this program we will see the addition of two numbers using two different methods. In first program we specify the values of two numbers in the program itself. And in second program take the both numbers entered by user and add. In third program we use add () function.

Adding the numbers using java programming is same logic as add the numbers using other programming languages. Adding the numbers means simply add the values in the variables.

For example:

```Numbers to Add: 20 and 50
Let Num1 = 20 and Num2= 50

Sum= Num1 + Num2
Sum= 20 + 50```

#### First Program: Add of two numbers

``````class Add
{
public static void main(String[] args)
{
int Num1,Num2,Sum;
Num1=20;
Num2=50;
Sum=Num1+Num2;
}
}
``````

Output:

`Addition of Num1 and Num2: 70`

The output of above program is 70 this is the addition of two numbers 20 and 50. but if you can see then you notice that in this program we put the values in the program itself. There are no choice for use to enter the values.

If you want to get the input values from users and use them in program then refer following program. In this program you get the input form users for addition.

#### Second Program: Addition of two numbers using Scanner

In this addition program we use Scanner class. Scanner is a java class which used for to take input from users.

``````import java.util.*;

{
public static void main(String[] args)
{
int Num1,Num2,Sum;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of Num1:");
Num1 = sc.nextInt();
System.out.println("Enter the value of Num2:");
Num2 = sc.nextInt();
Sum=Num1+Num2;
}
}
``````

output:

```Enter the value of Num1:
20
Enter the value of Num2:
50
Addition of Num1 and Num2: 70          ```

Above output is same as the first program’s output but here we take the input from user do not specify the values in the program itself. Next is, below program are same as above program but difference is that we use separate Add() function because it is helpful for reuse.

``````import java.util.*;

{
{
int sum;
sum=num1+num2;
return sum;
}
public static void main(String[] args)
{
int Num1,Num2;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of Num1:");
Num1 = sc.nextInt();
System.out.println("Enter the value of Num2:");
Num2 = sc.nextInt();
`Enter the value of Num1: 20 Enter the value of Num2: 50 Addition of Num1 and Num2: 70      `