我无法理解以下代码块。
int count = 0;
for (int i = 0; i < 3; i++){
count += (count++);
System.out.println("count = " + count);
System.out.println("i = " + i);
}
我的理解是循环运行三遍,执行以下操作
count = count + count
count = 1 + count
这转换为以下内容,因为 count 最初为 0:
count = 0 + 0
count = 1 + 0 = 1
count = 1 + 1 = 2
count = 1 + 2 = 3
count = 3 + 3 = 6
count = 6 + 1 = 7
输出如下,计数打印为 0。
count = 0
i = 0
count = 0
i = 1
count = 0
i = 2
有人可以向我解释一下吗?谢谢