Java - Sum Two Numbers

Requirement

  • Read two integer numbers from console
  • Add them together
  • Output the result

Demo

import java.util.Scanner;


public class Main {

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in); 
    System.out.print("Enter first Value:  ");
    int first = in.nextInt();
    System.out.print("Enter second Value:  ");
    int second = in.nextInt();
    System.out.print("The sum is:  " + (first+second));
    in.close();//w w  w . j a  v a2s .c  om
  }

}

Related Topic