Sum of two numbers using Scanner in Java.
Java Program to Add two Numbers
Here we will see Two programs to Add two Integer numbers, In the First program we specify the value of both the numbers in the program...
EXAMPLE :-
import java.util.Scanner;
public class Add2 {
public static void main(String[] args) {
int number1, number2, sum;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a First Number :: ");
number1 = sc.nextInt();
System.out.println("Enter a Second Number :: ");
number2 = sc.nextInt();
sc.close();
sum = number1 + number2;
System.out.println("Sum of Two numbers : "+sum);
}
}
OUTPUT
Enter a First Number ::
21
Enter a Second Number ::
12
Sum of Two numbers : 33
No comments:
Post a Comment
Please do not any spam link in Comment Box