1. 程式人生 > 其它 >23、多維陣列

23、多維陣列

多維陣列

public class ArrayDemo08 {
    public static void main(String[] args) {
        //[4][2]
        /*
            1,2     array[0]
            3,4     array[1]
            5,6     array[2]
            7,8     array[3]
         */

        int[][] arrays = {{1,2},{3,4},{5,6},{7,8}};
        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();
        }
    }
}
public class ArrayDemo09 {
    public static void main(String[] args) {
        //[2][5]    兩行五列
        /*
            1,2,3,4,5   arrays[0]
            6,7,8,9,10  arrays[1]
         */

        int[][] arrays = {{1,2,3,4,5},{6,7,8,9,10}};

        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();
        }
    }
}