代码:
1 import java.util.*;
2 public class Main {
3 public static void main (String [] args) {
4 Scanner s=new Scanner(System.in);
5 double d1=s.nextDouble();
6 char op=s.next().charAt(0);
7 double d2=s.nextDouble();
8
9 switch(op) {
10 case ‘+‘:
11 {
12 System.out.println(d1+d2);
13 break;
14 }
15 case ‘-‘:
16 {
17 System.out.println(d1-d2);
18 break;
19 }
20 case ‘*‘:
21 {
22 System.out.println(d1*d2);
23 break;
24 }
25 case ‘/‘:
26 {
27 if(d2!=0)
28 System.out.println(d1/d2);
29 else
30 System.out.println("Dividend cannot be 0");
31 break;
32 }
33 default:
34 {
35 System.out.println("Illegal operator");
36 break;
37 }
38 }
39 }
40 }
原文:https://www.cnblogs.com/fandehui/p/11048419.html