Java Program To Add Two Numbers
Chapter:
Java Basics
Last Updated:
15-07-2016 09:45:25 UTC
Program:
/* ............... START ............... */
public class JavaAddTwoNumbers {
public static void main(String args[]) {
int x, y, z;
System.out.println("Enter two integers to calculate their sum ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
z = x + y;
System.out.println("Sum of entered integers = " + z);
}
}
/* ............... END ............... */
Output
Enter two integers to calculate their sum
2
3
Sum of entered integers = 5
Notes:
-
Java program accepts numbers as user input from the command line using java.util.Scanner class and added up to get the result.
Tags
Add Two Numbers