package test; import java.util.Scanner; public class calculator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入:"); while (scanner.hasNextDouble()) { double sum = 0; double i = scanner.nextDouble(); double j = scanner.nextDouble(); char name = scanner.next().charAt(0); switch (name) { case '+': add(i, j); break; case '*': multiply(i, j); break; case '-': minus(i, j); break; case '/': if (j == 0) { System.out.println("0不能被除"); break; } else divide(i, j); break; default: System.out.println("啥也不是!"); break; } System.out.println("输入任意字母退出"); } scanner.close(); } public static void add(double i,double j) { double sum = i + j; System.out.println("你所计算的结果为" + sum); } public static void multiply(double i,double j){ double sum = i * j; System.out.println("你所计算的结果为" + sum); } public static void divide(double i, double j){ double sum = i / j; System.out.println("你所计算的结果为" + sum); } public static void minus(double i, double j){ double sum = i - j; System.out.println("你所计算的结果为" + sum); } }
这是我的代码
运行结果只能输入 没有输出结果
求大佬解答
我是萌新