Java program to add two integers

Java Programming Java8Object Oriented ProgrammingJava Technologies

The + operator in Java is used to multiply two numbers. Read required numbers from the user using Scanner class and add these two integers using the + operator.

Example

import java.util.Scanner;
public class AddinTwoNumbers {
   public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the value of the first number ::");
      int a = sc.nextInt();
      System.out.println("Enter the value of the first number ::");
      int b = sc.nextInt();
      int result = a+b;
      System.out.println("Sum of the given two numbers is ::"+result);
   }
}

Output

Enter the value of the first number ::
5564
Enter the value of the first number ::
2234
Sum of the given two numbers is ::7798
raja
Published on 25-Apr-2018 13:20:08
Advertisements