简易计算器

写一个计算器,要求实现加减乘除功能,并且循环接收新的数据,通过用户交互实现。

package com.steven.method;

import java.util.Scanner;

public class Calculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String grade = scanner.next();
        double a = scanner.nextDouble();
        double b = scanner.nextDouble();
        result(grade, a, b);
    }

    public static void result(String grade, double a, double b){
        switch (grade){
            case "+":
                System.out.println(a+b);
                break;
            case "-":
                System.out.println(a-b);
                break;
            case "*":
                System.out.println(a*b);
                break;
            case "/":
                System.out.println(a/b);
                break;
            case "%":
                System.out.println(a%b);
            break;
            default:
                System.out.println("输入错误");
        }
    }
}

 

posted @ 2020-06-02 22:49  玉面小飞龙  阅读(126)  评论(0编辑  收藏  举报