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 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗