# 写一个计器，要求实现加减乘除功能，并且能够循环接收新的数据，通过用户交互实现(Write a counter, which is required to realize the function of addition, subtraction, multiplication and division, and can receive new data circularly, which can be realized through user interaction)-其他

## 写一个计器，要求实现加减乘除功能，并且能够循环接收新的数据，通过用户交互实现(Write a counter, which is required to realize the function of addition, subtraction, multiplication and division, and can receive new data circularly, which can be realized through user interaction)

package base.method;import java.util.Scanner;public  class Demo06 {    //写一个计器，要求实现加减乘除功能，并且能够循环接收新的数据，通过用户交互实现    public static void main(String[] args) {        Scanner scanner=new Scanner(System.in);        String isNext = "y";//定义字符串，作为while初始执行条件        while (isNext.equals("y")){            double i1=0;//操作数1            double i2=0;//操作数2            double result=0;//结果            String oper="+";//运算符，通过switch            System.out.println("请输入第一个操作数：");            i1=scanner.nextDouble();            System.out.println("请输入运算符：");            oper=scanner.next();            System.out.println("请输入第二个操作数：");            i2=scanner.nextDouble();            switch (oper){                case "+":                    System.out.println("您选择"+oper+"运算符：");                    result=add(i1,i2);                    System.out.println("结果为"+i1+oper+i2+"="+result);                    break;                case "-":                    System.out.println("您选择"+oper+"运算符：");                    result=sub(i1,i2);                    System.out.println("结果为"+i1+oper+i2+"="+result);                    break;                case "*":                    System.out.println("您选择"+oper+"运算符：");                    result=mul(i1,i2);                    System.out.println("结果为"+i1+oper+i2+"="+result);                    break;                case "/":                    if (i2==0){                    System.out.println("除数不能为0");                }else{                    System.out.println("您选择"+oper+"运算符：");                    result=div(i1,i2);                    System.out.println("结果为"+i1+oper+i2+"="+result);                }                break;                default:                    System.out.println("输入运算符错误！");                    break;            }            System.out.println("是否继续计算?(输入y继续，其他任意键结束)：");            /*String a=scanner.next();//终止条件            if (a.equals("n")||a.equals("N")){                System.out.println("感谢使用本计算器！");                break;            }*/            isNext=scanner.next();//终止条件        }        System.out.println("感谢使用本计算器！");        scanner.close();    }    public static double add(double num1,double num2){        return num1+num2;    }    public static double sub(double num1,double num2){        return num1-num2;    }    public static double mul(double num1,double num2){        return num1*num2;    }    public static double div(double num1,double num2){        return num1/num2;    }}
————————
package base.method;import java.util.Scanner;public  class Demo06 {    //写一个计器，要求实现加减乘除功能，并且能够循环接收新的数据，通过用户交互实现    public static void main(String[] args) {        Scanner scanner=new Scanner(System.in);        String isNext = "y";//定义字符串，作为while初始执行条件        while (isNext.equals("y")){            double i1=0;//操作数1            double i2=0;//操作数2            double result=0;//结果            String oper="+";//运算符，通过switch            System.out.println("请输入第一个操作数：");            i1=scanner.nextDouble();            System.out.println("请输入运算符：");            oper=scanner.next();            System.out.println("请输入第二个操作数：");            i2=scanner.nextDouble();            switch (oper){                case "+":                    System.out.println("您选择"+oper+"运算符：");                    result=add(i1,i2);                    System.out.println("结果为"+i1+oper+i2+"="+result);                    break;                case "-":                    System.out.println("您选择"+oper+"运算符：");                    result=sub(i1,i2);                    System.out.println("结果为"+i1+oper+i2+"="+result);                    break;                case "*":                    System.out.println("您选择"+oper+"运算符：");                    result=mul(i1,i2);                    System.out.println("结果为"+i1+oper+i2+"="+result);                    break;                case "/":                    if (i2==0){                    System.out.println("除数不能为0");                }else{                    System.out.println("您选择"+oper+"运算符：");                    result=div(i1,i2);                    System.out.println("结果为"+i1+oper+i2+"="+result);                }                break;                default:                    System.out.println("输入运算符错误！");                    break;            }            System.out.println("是否继续计算?(输入y继续，其他任意键结束)：");            /*String a=scanner.next();//终止条件            if (a.equals("n")||a.equals("N")){                System.out.println("感谢使用本计算器！");                break;            }*/            isNext=scanner.next();//终止条件        }        System.out.println("感谢使用本计算器！");        scanner.close();    }    public static double add(double num1,double num2){        return num1+num2;    }    public static double sub(double num1,double num2){        return num1-num2;    }    public static double mul(double num1,double num2){        return num1*num2;    }    public static double div(double num1,double num2){        return num1/num2;    }}