Java Program to Add two Numbers

In this Java program, you'll learn how to read two integer numbers from the console using a Scanner. After addition, the final sum is displayed on the screen.

Java Program to Add Two Numbers


import java.util.Scanner;

 * Java Program to Add two Numbers
 * @author
public class JavaProgramAddTwoNumber {
    public static void main(String[] args) {

        int num1, num2, sum;
        try (Scanner sc = new Scanner( {
            System.out.println("Enter First Number: ");
            num1 = sc.nextInt();

            System.out.println("Enter Second Number: ");
            num2 = sc.nextInt();
            sum = num1 + num2;
            System.out.println("Sum of these numbers: " + sum);
Enter First Number: 
Enter Second Number: 
Sum of these numbers: 30

Related Java Programs