forked from szabgab/code-maven.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputCalculator.java
More file actions
38 lines (31 loc) · 1.05 KB
/
Copy pathInputCalculator.java
File metadata and controls
38 lines (31 loc) · 1.05 KB
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class InputCalculator {
public static void main(String[] args){
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("First number: ");
int x = Integer.parseInt(br.readLine());
System.out.print("Second number: ");
int y = Integer.parseInt(br.readLine());
System.out.print("Operator: ");
String op = br.readLine();
int z;
if (op.equals("+")) {
z = x+y;
} else if (op.equals("-")){
z = x-y;
} else if (op.equals("*")){
z = x*y;
} else if (op.equals("/")){
z = x/y;
} else{
throw new java.lang.Error("Operator not recognized");
}
System.out.println("Result: " + z);
} catch (IOException e) {
e.printStackTrace();
}
}
}