Java Program to Add Two Integers

In this example, we are giving a program to add two integer numbers.


To add two integer numbers:

  1. # To print an Integer given by user
  2. public class AddTwoIntegers {
  3. public static void main(String[] args) {
  4. int first = 10;
  5. int second = 20;
  6. int sum = first + second;
  7. System.out.println("The sum is: " + sum);
  8. }
  9. }

Output:

Enter two numbers: 10 20
The sum is: 30