-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.java
40 lines (31 loc) · 1013 Bytes
/
Calculator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Q.Create Java Program for simple calculator with user input .
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
int n1, n2;
int op, cal;
System.out.println("enter two numbers=");
try (Scanner R = new Scanner(System.in)) {
n1 = R.nextInt();
n2 = R.nextInt();
System.out.println("select operation");
op = R.nextInt();
}
if (op == 1) {
cal = n1 + n2;
System.out.println("ADDITION=" + cal);
} else if (op == 2) {
cal = n1 - n2;
System.out.println("SUBSTRACTION=" + cal);
} else if (op == 3) {
cal = n1 * n2;
System.out.println("MULTIPLICATION=" + cal);
} else if (op == 4) {
cal = n1 / n2;
System.out.println("DIVISION=" + cal);
} else {
cal = n1 % n2;
System.out.println("Remander=" + cal);
}
}
}