控制台计算器-有BUG版
import java.util.Scanner; public class z1{ public static void main(String args[]){ Scanner scanner=new Scanner(System.in); System.out.println("请输入第一个数字:"); double one=scanner.nextDouble(); System.out.println("请输入第二个数字:"); double two=scanner.nextDouble(); System.out.println("请选择运算符:"); System.out.println("1:加 2:减 3:乘 4:除"); double operator=scanner.nextDouble(); double result=0; double remainder=0; switch((int)operator){ case 1: result=one+two; break; case 2: result=one-two; break; case 3: result=one*two; break; case 4: result=one/two; remainder=one%two; break; } if (operator==4){ System.out.println("结果为:"+result+"余数为:"+remainder); }else System.out.println("结果为:"+result); scanner.close(); } }
本文来自博客园,作者:xiaoyongdata(微信号:xiaoyongdata),转载请注明原文链接:https://www.cnblogs.com/xiaoyongdata/p/16716262.html