java数组使用 三 循环数组元素


package array;

public class Demo03 {
    public static void main(String[] args) {
        int[] arrays = {1, 2, 3, 4, 5, 6,7, 8, 9, 10, 11, 12, 13, 14};
        test();

        printArray(arrays);
    }

    public static void test() {
        int[] arrays = {1, 2, 3, 4, 5, 67, 8, 9, 10, 11, 12, 13, 41};

//增强性 for循环
        for (int array : arrays) {
            System.out.print(array+"	");//1	2	3	4	5	67	8	9	10	11	12	13	41
        }
        System.out.println();
    }


//打印数组元素
     public  static  void printArray(int[] arrays){
         for (int i = 0; i < arrays.length; i++) {
             System.out.print(arrays[i]+"	");//1	2	3	4	5	6	7	8	9	10	11	12	13	14
         }
     }
}

运行结果

原文地址:https://www.cnblogs.com/d534/p/15077959.html