Java Program to Add Two Integers

To understand this example, you should have the knowledge of the following Java programming topics:


Example: Program to Add Two Integers

Output:

Enter two numbers
10 20
The sum is: 30

In this program, two integers 10 and 20 are stored in integer variables first and second respectively.

Then, first and second are added using the + operator, and its result is stored in another variable sum.

Finally, sum is printed on the screen using println() function.