好,所以变量current
是一个运算符(+ - * /%)
和t1 = stack.pop()
是字符串形成中的数字
t2 = stack.pop()
也是字符串形成中的数字
我需要进行数学运算t2 current t1
(t2"运算符" t1,基本上)
你会怎么做呢?提前谢谢!
答案 0 :(得分:3)
简单的事情:
enum operation {
SUM,
SUB,
DIV,
MUL,
}
static String performOperation(operation op, String t1, String t2) {
// parse t1 & t2 into integers or whatever you use
switch(op) {
case SUM:
//do sum
break;
case SUB:
//do substraction
break;
// handle all of them....
}