我正在创建基本计算器,要求用户输入第一个值、最后一个值和操作,例如 +、- 、* 这是代码
Scanner input= new Scanner(System.in);
double firstval, lastval,result;
Scanner cal = new Scanner(System.in);
System.out.println("Please enter the first value ? ");
firstval= cal.nextDouble();
System.out.println("Please enter the last value ? ");
lastval= cal.nextDouble();
System.out.println("Please enter the action ? ");
// how to store action ( +, - ,*) in varibale to perform result ?
String action = cal.next();
result= firstval + action + lastval;
System.out.println(result);
谢谢您并期待积极的回应
尝试使用
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
代替扫描仪。