-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
34 lines (26 loc) · 871 Bytes
/
Calculator.java
File metadata and controls
34 lines (26 loc) · 871 Bytes
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
import java.util.*;
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter The 1st Numer ");
int n1 = sc.nextInt();
System.out.println("Enter The 2nd Number");
int n2 = sc.nextInt();
System.out.println("Enter The Operator");
char o = sc.next().charAt(0); // charAt(0) is used to get the first character of the string entered by the
// user
int r = 0;
if (o == '+') {
r = n1 + n2;
} else if (o == '-') {
r = n1 - n2;
} else if (o == '*') {
r = n1 * n2;
} else if (o == '/') {
r = n1 / n2;
} else {
System.out.print("Invalid Operator");
}
System.out.print(r);
}
}