Java – Calculate Sum of Two Numbers
Write A Java Program to calculate the sum of two numbers. In the first program, we have predefined values for two integer variables and calculate the sum of them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14  | public class AddNumbers {    public static void main(String[] args) {       int num1 = 20;       int num2 = 25;       int sum;       //Calculate sum       sum = num1 + num2;       System.out.println("Sum is: " + sum);    } }  | 
Compile and run this program:
javac AddNumbers.java java AddNumbers 
Output:
Sum is: 45