谢谢
------最佳解决方案--------------------------------------------------------
下面是一个简单的程序:
import java.util.*;
public class calc {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("*****************简单计算器****************");
System.out.println("*\t\t\t\t\t*");
System.out.println("* 使用说明: 1.加法 2.减法 3.乘法 4.除法 * 5.退出");
System.out.println("*\t\t\t\t\t*");
System.out.println("*****************************************");
for(int i=0;i<100;i++){
System.out.print("\n请选择运算规则:");
int num = input.nextInt();
if (num == 5) {
break;
}
switch(num){
case 1:
System.out.println("\n******你选择了加法******\n");
System.out.print("请输入第1个加数:");
int jiashu1 = input.nextInt();
System.out.print("请输入第2个加数:");
int jiashu2 = input.nextInt();
System.out.println("运算结果为:" + jiashu1 + " + " + jiashu1 + " = " + (jiashu1 + jiashu2));
break;
case 2:
System.out.println("\n******你选择了减法******\n");
System.out.print("请输入被减数:");
int jianshu1 = input.nextInt();
System.out.print("请输入减数:");
int jianshu2 = input.nextInt();
System.out.println("运算结果为:" + jianshu1 + " - " + jianshu2 + " = " + (jianshu1 - jianshu2));
break;
case 3:
System.out.println("\n******你选择了乘法******\n");
System.out.print("请输入第1个因数:");
int chengfa1 = input.nextInt();
System.out.print("请输入第2个因数:");
int chengfa2 = input.nextInt();
System.out.println("运算结果为:" + chengfa1 + " * " + chengfa2 + " = " + (chengfa1 * chengfa2));
break;
case 4:
System.out.println("\n******你选择了除法******\n");
System.out.print("请输入被除数:");
double chufa1 = input.nextInt();
System.out.print("请输入除数:");
double chufa2 = input.nextInt();
System.out.println("运算结果为:" + chufa1 + " / " + chufa2 + " = " + (chufa1 / chufa2) + " 余 " + (chufa1 % chufa2));
break;
default:
System.out.println("\n你的选择有错,请重新选择!");
break;
}
}
}
}
------其他解决方案--------------------------------------------------------
恩呢,正解啊
------其他解决方案--------------------------------------------------------
自己想想啊 又不难
------其他解决方案--------------------------------------------------------
楼上正解,不过有点简单,不能实现连续运算和混合运算。
------其他解决方案--------------------------------------------------------
输入一个合法的表达式,然后调用ScriptEngine来求值