简单计算器的实现

计算器实现

package com.snowMoon;

import java.util.Scanner;

public class Calculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入你要进行的运算方法");
        System.out.println("1.加法\t2.减法\t3.乘法\t4.除法");
        int i = scanner.nextInt();
        if (i<=4&&i!=0){
            System.out.println("输入你需要进行运算的数");
            double a = scanner.nextDouble();
            double b = scanner.nextDouble();

            switch (i) {
                case 1:
                    System.out.println("结果为" + (a + b));
                    break;
                case 2:
                    System.out.println("结果为" + (a - b));
                    break;
                case 3:
                    System.out.println("结果为" + (a * b));
                    break;
                case 4:
                    System.out.println("结果为" + (a / b));
                    break;
            }
        }else{
            System.out.println("不合法的输入");
        }
    }
}

简单计算器的实现

上一篇:(三十四)c#Winform自定义控件-下拉框


下一篇:React Hook 中 useState 异步回调获取不到最新值及解决方案