i ++&和i ++之间的区别是什么? ++我在for循环(Java)? [英] what is the difference between i++ & ++i in for loop (Java)?
问题描述
你好,我刚开始学习Java,现在我正在进行循环语句。我不明白++ i i ++在for循环语句中是如何工作的。
hello, I've just started learning Java and now I'm into for loop statement. I don't understand how ++i i++ works in a for loop statement.
我的意思是它们如何在数学运算中起作用,如加法和减法。我希望有人会向我解释这个。
I mean how they work in mathematics operations like addition and subtraction. I hope some one will explain this to me.
推荐答案
他们都增加了数字。 ++ i
相当于 i = i + 1
。
They both increment the number. ++i
is equivalent to i = i + 1
.
i ++
和 ++ i
非常相似但不完全相同。两者都递增数字,但 ++ i
在计算当前表达式之前递增数字,而 i ++
递增数字在计算表达式之后。
i++
and ++i
are very similar but not exactly the same. Both increment the number, but ++i
increments the number before the current expression is evaluted, whereas i++
increments the number after the expression is evaluated.
int i = 3;
int a = i++; // a = 3, i = 4
int b = ++a; // b = 4, a = 4
这篇关于i ++&和i ++之间的区别是什么? ++我在for循环(Java)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!