机制是什么?

问题描述 投票:-3回答:1

执行下面的程序后,打印5条Hello Java行。所以我知道i ++有打印10行。我需要在此程序中执行i + = 2的职责。

 class Example{
      public static void main(String args[]){
            for(int i=0; i<10; i+=2){
            System.out.println("Hello Java");
            }
       }
   }
java loops for-loop
1个回答
0
投票
for(int i = 0; // i is an variable integer, which is 0 from the start
    i < 10;    // if i is 10 or above, the loop is finished, else the code runs
    i += 2)    // after the code is ran, 2 will be added to the variable i 
{/*...*/}
© www.soinside.com 2019 - 2024. All rights reserved.