In this Java program, it calculates the sum of two numbers and prints the result
In this program
- We declare and initialize two integer variables, firstNumber and secondNumber, with the values 10 and 20, respectively.
- We calculate the sum of these two numbers and store the result in the sum variable.
- Finally, we use System.out.println to display the result, which will be "Addition is: 30" in this case.
public class SumOfNumbers {
public static void main(String[] args) {
int a = 10;
int b = 20;
int ans = a + b;
System.out.println("Addition is : " + ans);
}
}
Follow Us