In this Java program, you will learn how to add two integers or numbers in java. After performing the addition, the final sum is displayed on the display.
//Java Program to Add Two Integers
public class JavaPrograms {
public static void main(String[] args) {
int first = 111;
int second = 222;
System.out.println("Add Number: " + first + " and " + second);
// addition of two numbers
int sum = first + second;
System.out.println("The sum is: " + sum);
}
}
Add Number: 111 and 222
The sum is: 333
In this program, two integers 111 and 222 are stored in integer variables first and second respectively.
Then, the first and second are added using the + operator, and its output is stored in another variable named sum.
Finally, the sum is printed on the display using println()
function.
Comments