一个Java三维数组的最简单例子

package array;

public class multiDimensionArray {

    public static void main(String[] args) {

        int [][][] array2 = {{ {1,2,3}}, {{4,5,6}}, {{7,8,9}}};
        int size = array2.length;
        System.out.println("size: " + size);
        
        for( int i = 0; i < size; i++){
            int[][] twoDimension = array2[i];
            System.out.println("inner size: " + twoDimension.length);
            for( int j = 0; j < twoDimension.length; j++){
                int [] threeDimension = twoDimension[j];
                for( int z = 0; z < threeDimension.length; z++){
                    System.out.println("i,j,j: " + "[" + i + "],[" + j + "],[" + z + "]:->" + 
                            threeDimension[z]);
                }
            }
        }
    }
}

输出:

size: 3
inner size: 1
i,j,j: [0],[0],[0]:->1
i,j,j: [0],[0],[1]:->2
i,j,j: [0],[0],[2]:->3
inner size: 1
i,j,j: [1],[0],[0]:->4
i,j,j: [1],[0],[1]:->5
i,j,j: [1],[0],[2]:->6
inner size: 1
i,j,j: [2],[0],[0]:->7
i,j,j: [2],[0],[1]:->8
i,j,j: [2],[0],[2]:->9
上一篇:Perl快捷删除数组重复元素


下一篇:登录WEB时提示Mysql数据库无法连接!