【发布时间】:2015-06-04 22:36:56
【问题描述】:
运行这个程序后,我得到 'a' 的值为 5 而不是 6。为什么?
public class Test
{
public static void main(String args[])
{
int a=5;
a=a++; //post increment operator
System. out. println (a); //Output
}
}
为什么这是程序的输出?
【问题讨论】:
-
您在第一句话中回答了标题问题。顺便说一句,可以在这个网站上找到答案。这是因为它保存旧值,递增,然后返回您分配的旧值。
-
你认为答案应该是什么?
-
仅供参考,您真的只需要 google
java post increment operator就可以在 StackOverflow 上找到大量重复项,此外还有各种其他网站详细解释了后增量运算符的工作原理。 -
What is the output of the program?5 -
@CodeCamper 输出是 5 而不是 6。为什么?
标签: java assignment-operator post-increment