题目请教
大佬们这个题目为什么报错了,在vscode上运行并没有报错 题目是150.逆波兰表达式. 报错内容是下面的图片
public int evalRPN(String[] tokens) {
Stack<Integer> stack = new Stack<>();
for (int i = 0; i < tokens.length; i++) {
if (tokens[i] == "+" || tokens[i] == "-" || tokens[i] == "*" || tokens[i] == "/") {
if (tokens[i] == "+") {
int temp = stack.pop() + stack.pop();
stack.push(temp);
}
if (tokens[i] == "-") {
int temp = -stack.pop() + stack.pop();
stack.push(temp);
}
if (tokens[i] == "*") {
int temp = stack.pop() * stack.pop();
stack.push(temp);
}
if (tokens[i] == "/") {
int up = stack.pop();
int down = stack.pop();
stack.push(down / up);
}
} else {
stack.push(Integer.valueOf(tokens[i]));
}
}
return stack.pop();
}