Java Program to Add Two Numbers

In this program, we will take two values from user as input and calculate their sum.

  1. //Java program to add two integers
  2. import java.util.Scanner;
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner first = new Scanner(;
  6. System.out.println("Enter first number: ");
  7. int a = first.nextInt();
  8. Scanner second = new Scanner(;
  9. System.out.println("Enter second number: ");
  10. int b = second.nextInt();
  11. int sum = a + b;
  12. System.out.println("The sum is: " + sum);
  13. }
  14. }

Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

Join Our Facebook Group

Share this example

Download Android App

download android app

Popular Java Examples is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube