i ++&之间有什么区别? ++ i在for循环中?

编程入门 行业动态 更新时间:2024-10-27 10:19:47
本文介绍了i ++&之间有什么区别? ++ i在for循环中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我刚刚开始学习Java,现在我进入了for循环语句.我不明白++i和i++在for循环中如何工作.

I've just started learning Java and now I'm into for loop statements. I don't understand how ++i and i++ works in a for-loop.

它们如何在加减运算等数学运算中起作用?

How do they work in mathematics operations like addition and subtraction?

推荐答案

它们都增加数字. ++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循环中?

本文发布于:2023-07-29 09:03:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239324.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   amp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!