Java Program to Add Two Integers

Write a program to add two Integers.

public class AddTwoIntegers {

    public static void main(String[] args) {
        
        int first = 20;
        int second = 30;

        System.out.println("Enter two numbers: " + first + " " + second);
        int sum = first + second;

        System.out.println("The sum is: " + sum);
    }
}
Output
Enter two numbers: 20 30
The sum is: 50

This program is pity straight forward. We are adding two numbers and both numbers are hard coded.

Similarly, write a program to add two numbers. But this time the input should come from keyboard.

Hint: Use Scanner class to take input from keyboard.

Leave a Reply