Java多维数组(二维数组,包含方法的重载)

package com.array;

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

        printArrays(arrays[3]);
        System.out.println("\n"+"==================");
        printArrays(arrays);

    }
/**
    public static void printArrays(int[] arrays){    //增强型for循环
        for(int x:arrays) System.out.print(x+" ");
    }
 */
    public static void printArrays(int[] arrays){
        for (int i = 0; i < arrays.length; i++) {
            System.out.print(arrays[i]+" ");
        }
    }

    public static void printArrays(int[][] arrays){
        for (int i = 0; i < arrays.length; i++) {
            for (int j = 0; j < arrays[i].length; j++) {
                System.out.print(arrays[i][j]+" ");
            }
            System.out.println();
        }
    }
}

 

posted @ 2021-11-26 16:04  バカなの  阅读(52)  评论(0编辑  收藏  举报