Java program to add two integers
https://www.theitroad.com
Here's an example Java program that adds two integers:
public class AddTwoIntegers { public static void main(String[] args) { int num1 = 5; int num2 = 10; int sum = num1 + num2; System.out.println("The sum of " + num1 + " and " + num2 + " is " + sum + "."); } }
In this example, we create two integer variables called num1
and num2
and assign them the values 5 and 10, respectively. We then add the two numbers together and store the result in a third variable called sum
. Finally, we print out the result to the console using the System.out.println()
method.
The output of this program will be:
The sum of 5 and 10 is 15.