如何使Java中的循环增加1以外的增量 [英] How to make for loops in Java increase by increments other than 1
本文介绍了如何使Java中的循环增加1以外的增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
for(j = 0; j <= 90; j ++){ }
工作正常。但是当你有这样一个for循环:
$ p $ for(j = 0; j <= 90; j + 3){ }
不起作用。有人可以向我解释这个吗?
解决方案
这是因为 If you have a for loop like this: It works fine. But when you have a for loop like this: it doesn't work. Could someone please explain this to me? That’s because
这篇关于如何使Java中的循环增加1以外的增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! j + 3
不会改变 j
的值。你需要用 j = j + 3
或 j + = 3
替换它,这样<$ c对于(j = 0; j <= c
$ p $ 90; j + = 3){}
for(j = 0; j<=90; j++){}
for(j = 0; j<=90; j+3){}
解决方案 j+3
doesn’t change the value of j
. You need to replace that with j = j + 3
or j += 3
so that the value of j
is increased by 3:for (j = 0; j <= 90; j += 3) { }
查看全文