java基础四则运算器

 public static void main(String[] args) {
      
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个数");
        double numberA = scanner.nextDouble();
        System.out.println("请输入运算符");
        String Symbol  = scanner.next();
        System.out.println("请输入另一个数");
        double numberB = scanner.nextDouble();



       switch (Symbol ){
            case "+":
                System.out.println((numberA+numberB));
                break;
            case "-":
                System.out.println((numberA-numberB));
                break;
            case "*":
                System.out.println((numberA*numberB));
                break;
            case "/":
                System.out.println((numberA/numberB));
                if(numberB==0){
                System.out.println("分母为零该运算不成立");
                }
                break;
                default:
                    System.out.println("不符合标准。");

        }

    }

输出结果

java基础四则运算器_第1张图片

你可能感兴趣的:(java基础四则运算器)