Write a Java program to add two integers
Java program to add two Integers
In this program, two integers 11 and 12 are stored in integer variables first and second respectively.
Then, first and second are added using the + operator, and its result is stored in another variable sum.
Finally, sum is printed on the screen using println() function.
- Program:
class Main {
public static void main(String[] args) {
System.out.println("Enter two numbers");
int first = 11;
int second = 12;
System.out.println(first + " " + second);
// add two numbers
int sum = first + second;
System.out.println("The sum is: " + sum);
}
}
- Output:
Enter two numbers 11 12 The sum is: 23
- Visit:
Write a Java program to print an Integer Here
0 comments