Simply two-dimensional array

1. Definition Format
     * A first definition format:
     * int [] [] = ARR new new  int [. 3] [. 4]; //   ARR which comprises three arrays each array element which has four 
    * The above code is quite 3 * defined in a two-dimensional array 4, i.e., the length of the array is three dimensional, two-dimensional array each element is an array of length 4
     * B format the second definition
     * int [] [] = ARR new new  int [. 3 ] [];
     * the second embodiment and a similar, except that the length of each array element of uncertainty
     * C defines a third format
     * int [] [] = {{ARR. 1, 2}, {3,4,5,6}, {7,8,9 }};
     * define three dimensional array elements, the array elements are three, respectively, {1,2}, { 3,4,5,6}, {7,8,9 } 
traverse the two-dimensional array 2. the 
public  class ArrayArrayDemo1 {
    public static void main(String[] args){
        int[][] arr={{12,58},{56,78,41},{0}};
        //System.out.println(arr[1][1]);
        for(int i=0;i<arr.length;i++){
            for(int j=0;j<arr[i].length;j++){
                System.out.print(arr[i][j]+"  ");
            }
            System.out.println();
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/cat520/p/11613403.html