cswork / OA打开练习工作台

PaycomOA #19

Q19. Java Boolean Short-Circuit

估计简单概念题评测数据准备中,可先阅读题面

考点(AI 标注)位运算

What will be the output of this Java program?

class SSBool {
    public static void main(String[] args) {
        boolean b1 = true, b2 = false, b3 = true;
        if (b1 & b2 | b2 & b3 | b2)            // Line 8
            System.out.print("ok ");
        if (b1 & b2 | b2 & b3 | b2 | b1)       // Line 10
            System.out.println("dokey");
    }
}
  • ok / dokey <- / ok dokey / compilation fails

Line 8 evaluates to false (no ok); line 10 ends with | b1 which is true, so dokey prints.