Java array of two-dimensional array

Two-dimensional array

  And create a two-dimensional array declaration

  Two-dimensional array initialization

  Two-dimensional array of references

  Case presentation

==========================================================================

 

Package com.vip.array; 

public  class ArrayDemo3 {
     public  static  void main (String [] args) {
         // two-dimensional array declaration
         // three kinds declaratively
         // Declare two-dimensional array of type int 
        int [] [ ] intArray;
         // 2. declared two-dimensional array of type float 
        float floatArray [] [];
         // 3. declared two-dimensional array of type double 
        double [] doubleArray []; 

        // create a three rows and four columns of type int array 
        intArray = new new  int [. 3] [. 4 ]; 
        System.out.println ( "intArray first element of the first row" + intArray [0] [0]);      //The first line of the first element 
        System.out.println ( "intArray first row of the second element" + intArray [0] [. 1]);      // first row of the second element 
        intArray [1] [2] = 9;     // assign the second row and third column element 
        System.out.println ( "the second row and third column element" intArray + [. 1] [2 ]); 

        // be created simultaneously declares the array 
        char [] [] = CH new new  char [. 3] [. 5 ];
         // when creating an array of type float, only specify the number of rows 
        floatArray = new new  float [. 3 ] []; 
        System.out.println (floatArray [ 0]);   // every row corresponds to a one-dimensional array, create 
        floatArray [0] = new new  a float [. 3];    // first row has three
        floatArray [. 1] = new new  a float [. 4];   // second row has four 
        floatArray [2] = new new  a float [. 5];   // third row has five columns 

        System.out.println (floatArray [ 0] [0 ]);
 //         System.out.println (floatArray [0] [. 3]); out of bounds array subscript 

        // two-dimensional array initialization 
        int [] [] NUM = {{l, 2,3}, {. 4, } 5,6, {9,8,7 }}; 
        System.out.println ( "first line num array, the elements of the second column" + num [0] [. 1 ]); 
        System.out.println ( " num is the number of rows of the array: "+ num.length); 
        System.out.println ( " digital num array column: "+ num [0 ] .length); 

        int[] [] = {Num1 {12,13,14}, {1,2}, {99}};    // number of elements in each row is different 
        System.out.println ( "num1 first line is the number of columns: "num1 + [0 ] .length); 
        System.out.println ( " number of columns of the second row is num1: "num1 + [. 1 ] .length); 

        // cycle of the output of the two-dimensional array contents 
        for ( int I = 0; I <num1.length; I ++ ) {
             for ( int J = 0; J <num1 [I] .length; J ++ ) { 
                of System.out.print (num1 [I] [J] + "" ); 
            } 
            System.out.println (); 
        } 
    } 
}

 

Guess you like

Origin www.cnblogs.com/mpp0905/p/11524469.html