for循环变形

时间:2021-09-06 02:19:27   收藏:0   阅读:8

public class fortext
{
  public static void main(String[] args){
    for(int i = 10; i > 10; i--){
    System.out.println("i = " + i); // 10 9 8 7 6 5 4 3 2 1
    }

    // 变形
    for(int i = 0;i < 10; i += 2){
      System.out.println("value1 = " + i); // 0 2 4 6 8
    }

    for(int i = 100;i > 0; i %= 3){
      System.out.println("value1 = " + i); //100 1 1 1........1 注意 1/3 结果还是1
    }
  }
}

原文:https://www.cnblogs.com/874162650-com/p/15228291.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!