in this program, you will learn how to add two numbers in java here we are taking three variables a and b for the value and the sum to store the value.
Basic Java Program To Add Two Numbers
public class Add
{
public static void main(String[] args)
{
int a = 5;
int b = 10;
int sum = a + b;
System.out.println(“The total is: ” + sum);
}
}
Output:
The total is: 30
here we performed addition of two numbers a and b which output stored in the sum variable.
In this program, we have taken the value of a is 10 and the value of b is 20 so the output will be 30.