a = a ++如何在java中工作 [英] How does a=a++ work in java
本文介绍了a = a ++如何在java中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最近我遇到了这段Java代码:
Recently I came across this piece of Java code:
int a=0;
for(int i=0;i<100;i++)
{
a=a++;
}
System.out.println(a);
为'a'打印的值为0.但是在C的情况下,'a'的值为'结果是100。
The value printed for 'a' is 0. However in case of C, the value for 'a' comes out to be 100.
我无法理解为什么在Java的情况下值为0。
I am not able to understand why the value is 0 in case of Java.
推荐答案
a = a++;
从递增 a
开始,然后恢复 a
到旧值,因为 a ++
返回未递增的值。
starts with incrementing a
, and then reverting a
to the old value as a++
returns the not incremented value.
简而言之,它在Java中没有任何作用。如果你想增加,只使用这样的后缀运算符:
In short it does nothing in Java. If you want to increment, use only the postfix operator like this :
a++;
这篇关于a = a ++如何在java中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文