• java学习笔记(七):for循环


    java的for循环和c++的for循环类似

    1 public class Test {
    2    public static void main(String args[]) {
    3       for(int x = 10; x < 20; x = x+1) {
    4          System.out.print("value of x : " + x );
    5          System.out.print("
    ");
    6       }
    7    }
    8 }

    运行输出:

    value of x : 10
    value of x : 11
    value of x : 12
    value of x : 13
    value of x : 14
    value of x : 15
    value of x : 16
    value of x : 17
    value of x : 18
    value of x : 19

    Java 引入了一种主要用于数组的增强型 for 循环。

     1 public class Puppy{
     2     public static void main(String[] args){
     3         int[] Nums = {10,20,30,40,50,60};
     4         for(int x : Nums){
     5             System.out.print(x);
     6             System.out.print(",");
     7         }
     8 
     9         System.out.println();
    10         String[] Names = {"Jacky","Tom","Lily"};
    11         for(String name : Names){
    12             System.out.print(name);
    13             System.out.print(',');
    14         }
    15     }
    16 }

    运行输出:

    10,20,30,40,50,60,
    Jacky,Tom,Lily,
  • 相关阅读:
    简明python_Day2_字典、集合、模块、类、编程习惯
    测试2T2
    测试2T1
    bzoj2761
    一元三次方程求根公式及韦达定理
    状压DP入门——铺砖块
    高精度模板
    测试1T3
    测试1T2
    测试1T1
  • 原文地址:https://www.cnblogs.com/zylq-blog/p/7742086.html
Copyright © 2020-2023  润新知