Write a Java Program For the Addition of Two Integers:
Here are simple programs to add two numbers:
import java.util.Scanner; // import the Scanner class
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); // create a Scanner object
System.out.print("Enter the first number: ");
int num1 = scanner.nextInt(); // read the first number
System.out.print("Enter the second number: ");
int num2 = scanner.nextInt(); // read the second number
int sum = num1 + num2; // calculate the sum
System.out.println("The sum of the two numbers is: " + sum); // print the result
}
}
This is a Simple program for adding two integers (Numbers) in java.
Here, Scanner is Used to take input from the user.
Here is The Output Of the Program:
Enter the first Number: 1
Enter the second Number: 2
The Sum is: 3
-----------------------------------------------------------------------------------------------------------------------------
Queries Solved in this article:
- Java code for addition
- addition of two numbers in java
- write a java code for adding two integers
- java basics
- java program for addition
- basic java program for addition.
- what is a scanner in java
- how to take input and add two integers in java
- simple addition program in java
- how to add two integers in java
- how to take input from users in java
- Basics java programs
- java basic
- how to use scanner in java.

0 Comments