在Java中做什么和做什么?

use*_*051 1 java

我正在查看一段我没写过的Java代码,并注意到它在一些地方包含了&.它是一个从中缀到后缀符号转换器的代码.

如果我把这段代码放在Eclipse中它不喜欢这些&s并为它们创建错误,错误就是&amp cannot be resolved as a variable.

继承人的代码

public static String[] infixToRPN(String[] inputTokens) {
    ArrayList<String> out = new ArrayList<String>();
    Stack<String> stack = new Stack<String>();
    // For all the input tokens [S1] read the next token [S2]
    for (String token : inputTokens) {
        if (isOperator(token)) {
            // If token is an operator (x) [S3]
            while (!stack.empty() &amp;&amp; isOperator(stack.peek())) {
                // [S4]
                if ((isAssociative(token, LEFT_ASSOC) &amp;&amp; cmpPrecedence(
                        token, stack.peek()) <= 0)
                        || (isAssociative(token, RIGHT_ASSOC) &amp;&amp; cmpPrecedence(
                                token, stack.peek()) < 0)) {
                    out.add(stack.pop());   // [S5] [S6]
                    continue;
                }
                break;
            }
            // Push the new operator on the stack [S7]
            stack.push(token);
        } else if (token.equals("(")) {
            stack.push(token);  // [S8]
        } else if (token.equals(")")) {
            // [S9]
            while (!stack.empty() &amp;&amp; !stack.peek().equals("(")) {
                out.add(stack.pop()); // [S10]
            }
            stack.pop(); // [S11]
        } else {
            out.add(token); // [S12]
        }
    }
    while (!stack.empty()) {
        out.add(stack.pop()); // [S13]
    }
    String[] output = new String[out.size()];
    return out.toArray(output);
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*aux 15

您是从编码不良的网站复制粘贴代码.这&amp;应该替换为&符号(&).

在HTML中,你不能简单地写&,因为这是一个转义字符.因此,在历史上,他们发明了&符号的逃逸序列,即:&amp;.这就是网站不幸地向您展示的内容.

所以,回答这个问题:&amp;&amp;应该是:&&.那是逻辑AND运算符.