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(System.in);
  6. System.out.println("Enter first number: ");
  7. int a = first.nextInt();
  8. Scanner second = new Scanner(System.in);
  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. }

Output
Output!
download android app

Popular Java Examples









codesadda.com

Codesadda.com 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