This is an example program that demonstrates how you can perform the addition of two user given numbers in Java.
In this program first we are taking two integer numbers from the user, and then displaying the result of addition into the console.
Program
import java.util.Scanner; public class NumberAddition { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Take first number System.out.println("Enter 1st number : "); int num1 = scanner.nextInt(); // Take second number System.out.println("Enter 2nd number : "); int num2 = scanner.nextInt(); System.out.println("Result = " + (num1 + num2)); } }
Output
Enter 1st number : 10
Enter 2nd number : 40
Result = 50