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


import java.util.Scanner;

public class Demo{
    public static void main(String[] args) {
        for (int i = 0; i < 50; i++) {
            Scanner sc = new Scanner(System.in);
            System.out.println("===============================");
            System.out.println("1.加法运算");
            System.out.println("2.减法运算");
            System.out.println("3.乘法运算");
            System.out.println("4.除法运算");
            System.out.println("===============================");
            System.out.println("请输入您要选择的计算方法提示数字:");
            int a = sc.nextInt();
            switch (a) {
                case 1:
                    System.out.println("请输入您的两个数字:");
                    add();
                    break;
                case 2:
                    System.out.println("请输入您的两个数字:");
                    subtract();
                    break;
                case 3:
                    System.out.println("请输入您的两个数字:");
                    multiplication();
                    break;
                case 4:
                    System.out.println("请输入您的两个数字:");
                    division();
                    break;
                default:
                    System.out.println("请输入数字!!!!!");
            }
        }
    }
    //加法
    public static void add() {
        Scanner sc1 = new Scanner(System.in);
        int s1 = sc1.nextInt();
        int s2 = sc1.nextInt();
        System.out.println("运算结果是:" + (s1 + s2));
    }
    //减法
    public static void subtract() {
        Scanner sc2 = new Scanner(System.in);
        int s1 = sc2.nextInt();
        int s2 = sc2.nextInt();
        System.out.println("运算结果是:" + (s1 - s2));
    }
    //乘法
    public static void multiplication() {
        Scanner sc3 = new Scanner(System.in);
        int s1 = sc3.nextInt();
        int s2 = sc3.nextInt();
        System.out.println("运算结果是:" + (s1 * s2));
    }
    //除法
    public static void division() {
        Scanner sc4 = new Scanner(System.in);
        int s1 = sc4.nextInt();
        int s2 = sc4.nextInt();
        System.out.println("运算结果是:" + (s1 / s2));
    }
}
原文地址:https://www.cnblogs.com/lhy8116/p/14183750.html