-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathOperation.java
More file actions
37 lines (33 loc) · 774 Bytes
/
Operation.java
File metadata and controls
37 lines (33 loc) · 774 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
35
36
37
package u001;
//import edu.princeton.cs.algs4.StdIn;
/**
* Created by HuGuodong on 2019/11/9.
*/
public class Operation {
public static double getResult(double a, double b, String op) {
double result = 0;
switch (op) {
case "+":
result = a + b;
break;
case "-":
result = a - b;
break;
case "*":
result = a * b;
break;
case "/":
result = a / b;
break;
}
return result;
}
public static void main(String[] args) {
double r = getResult(10, 20, "-");
System.out.println(r);
// double a = StdIn.readDouble();
// double b = StdIn.readDouble();
// String op = StdIn.readString();
// System.out.println("result is :" + getResult(a, b, op));
}
}