鱼少学习多摸

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 @   北海之上  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
/* 粒子吸附*/
点击右上角即可分享
微信分享提示