我正在学习 java 并尝试 Stack 的示例。这是代码:
import java.util.*;
public class StackTry {
static boolean checkParity (String expression,
String open, String close) {
Stack stack = new Stack();
StringTokenizer st = new StringTokenizer (expression, " \t\n\r\+/-(){}", true);
while (st.hasMoreTokens()) {
String tmp = st.nextToken();
if (tmp.equals(open)) stack.push(open);
if (tmp.isEmpty()) return true;
return false;
}
public static void main (String [] args) {
System.out.println (
checkRarity("a - (b - (c - a) / (b + c) - 2), "(", ")));
}
}
}
我在第 7 行收到错误,如何解决?
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
我按照建议编辑了代码,但是得到
Multiple markers at this line
- The method checkRarity(String, String) is undefined for the type
StackTry
- Syntax error on token ""a - (b - (c - a) / (b + c) - 2), "", , expected after
this token