少学习多摸鱼

day12- 练习(计算器的实现)

 1  public static void main(String[] args) {
 2         Scanner scanner = new Scanner(System.in);
 3         System.out.println("输入:");
 4         int x = scanner.nextInt();
 5         char a = scanner.next().charAt(0);
 6         int y = scanner.nextInt();
 7         switch (a){
 8             case '+':
 9                 sum(x,y);
10                 break;
11             case '-':
12                 sub(x,y);
13                 break;
14             case '*':
15                 mul(x,y);
16                 break;
17             case '/':
18                 div(x,y);
19                 break;
20             default:
21                 System.out.println("输入错误");
22         }
23     }
24     public static void sum(int a,int b){
25         System.out.println(a+b);
26     }
27     public static void sub(int a,int b){
28         System.out.println(a-b);
29     }
30     public static void mul(int a,int b){
31         System.out.println(a*b);
32     }
33     public static void div(int a,int b){
34         System.out.println(((double)a/b));
35     }

 

posted @ 2022-10-06 16:19  北海之上  阅读(27)  评论(0)    收藏  举报
/* 粒子吸附*/