zoukankan      html  css  js  c++  java
  • JAVA学习(增强For循环)

    4.4 增强for循环

    • jdk5引入,主要用于数组或集合的增强型for循环

    • 语法:

    for(声明语句:表达式)
    {
        //代码句子 
    • 声明语句:声明新的局部变量,该变量类型必须和数组的元素类型匹配。其作用域限定在循环语句块,其值与此时数组元素的值相等

    • 表达式:表达式是要访问的数组名,或者是返回值为数组的方法

    package com.kuangshen.struct;
    ​
    public class ForDemo05 {
        public static void main(String[] args) {
            int [] numbers = {10,20,30,40,50};
            //遍历数组的元素
            for (int x:numbers){
                System.out.println(x);
            }
        }
    }
  • 相关阅读:
    java后端
    2017-12-11
    二叉树与分治法整理
    javaweb
    安装docker
    爬虫
    lintcode
    DEEPlearning
    剑指offer_by牛客网
    DFS
  • 原文地址:https://www.cnblogs.com/cjybarcode/p/13155448.html
Copyright © 2011-2022 走看看