Java代码输出不同:按位和布尔运算符

时间:2017-12-19 22:15:46

标签: java integer bitwise-operators post-increment boolean-operations

以下两个JAVA代码正在打印两个不同的输出:

    int i = 0;
    boolean t = true;
    boolean f = false, b;
    b = (t | ((i++) == 0));
    b = (f | ((i += 2) > 0));
    System.out.println(i);

输出 3

    int i = 0;
    boolean t = true;
    boolean f = false, b;
    b = (t || ((i++) == 0));
    b = (f || ((i += 2) > 0));
    System.out.println(i);

输出 2

这背后的原因是什么?

0 个答案:

没有答案