Java Program to add two numbers


In this program, You will learn how to add two numbers using with scanner class in Java.


20 = 10 + 10

40 = 20 + 20


Example: How to add two numbers in Java

Run it Now
import java.util.Scanner;

class Main {
    public static void main(String args[]) {

        int a, b, s;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter Two Numbers :");
        a = sc.nextInt();
        b = sc.nextInt();

        s = a + b;

        System.out.println("\nSum is :" + s);

    }
}

Output:

Enter Two Numbers :10 20
Sum is :30