packagecom.song.method;importjava.util.Scanner;publicclassTest{publicstaticvoidmain(String[] args){//与用户交互,做加减乘除的计算器Scanner scanner =newScanner(System.in);double result =-1;double a, b;System.out.println("input operator(+ - * /):");String operator = scanner.next();//字符串不能用==比较while(operator.equals("+")|| operator.equals("-")|| operator.equals("*")|| operator.equals("/")){System.out.println("input first numbers:");
a = scanner.nextDouble();System.out.println("input second numbers:");
b = scanner.nextDouble();switch(operator){case"+":
result =add(a, b);break;case"-":
result =subtract(a, b);break;case"*":
result =multiply(a, b);break;case"/":
result =divide(a, b);break;}System.out.println("The resule:"+ result);System.out.println("input operator(+ - * /):");
operator = scanner.next();}}publicstaticdoubleadd(double a,double b){return a + b;}publicstaticdoublesubtract(double a,double b){return a - b;}publicstaticdoublemultiply(double a,double b){return a * b;}publicstaticdoubledivide(double a,double b){return a / b;}}
package com.song.method;import java.util.Scanner;public class Test { public static void main(String[] args) { //与用户交互,做加减乘除的计算器 Scanner scanner = new Scanner(System.in); double result = -1; double a, b; .