【发布时间】:2020-10-08 04:35:22
【问题描述】:
package com.company;
public class test {
public static void main(String[] args) {
int x=5, y=4, z;
int step1 = (++x + ++y);
int step2 = (y++ % 2);
z= step1*step2;
System.out.println(step1 + "*" + step2);
System.out.println(z);
}
}
这个程序打印11。我尝试内联 step1 和 step2 期望得到相同的结果,但它会打印 1。
package com.company;
public class test {
public static void main(String[] args) {
int x=5, y=4, z;
z= (++x + ++y) * y++ % 2;
System.out.println(z);
}
}
为什么输出不同?
【问题讨论】:
-
试试
z = (++x + ++y) * (y++ % 2);
标签: java