And adder array multidimensional array

Initialized

1. static initialization

  int [][]  a={{1,2,3},{8,4,6},{4,7,2}}

Memory Analysis

Package cn.array2; 

public  class to Test01 {
     public  static  void main (String [] args) {
         int [] [] A = { 
                { l, 2,3 },       
                { 1,8,6 }, 
                { 7,6,9 , 7,5 } 
        }; 
        int [] [] B = new new  int [. 3] [];    // disposed a first three-dimensional element, a second dimension unrestricted 
        B [0] = new new  int [. 3];          //
         B [. 1] = new new  int [. 3 ]; 
        B [ 2] =new int[5];
        b[0][0]=1;
        b[0][1]=2;
        b[0][2]=3;
        
        b[1][0]=1;
        b[1][1]=8;
        b[1][2]=6;
        b[2][0]=7;
        
        b[2][1]=6;
        b[2][2]=9;
        b[2][3]=7;
        b[2][4]=5;
        System.out.println(a[2][2]);
        
        
    }
}

Matrix (Matrix)   

Adding small sample two-dimensional array

Matrix.java

Package cn.array2; 

public  class the Matrix { 
    
    // array package adder 
    public  static  int [] [] the Add ( int [] [] A, int [] [] B) {        // Array method of the type defined return 
        int [] [] = C new new  int [a.length] [a.length];
         for ( int I = 0; I <c.length; I ++ ) {
             for ( int J = 0; J <c.length; J ++ ) { 
                C [I] [J] = A [I] [J] + B [I] [J]; 
            }     
        } 
        return C; 
    } 
    //A method of packaging an array of printing; 
    public  static  void Print ( int [] [] C) {
         for ( int I = 0; I <c.length; I ++ ) {
             for ( int J = 0; J <c.length; J ++ ) { 
                of System.out.print (C [I] [J] + "\ T" ); 
            } 
            System.out.println (); 
            
        } 
        
    } 
    
    public  static  void main (String [] args) {
         int [] [] A = { 
                { 1,2 }, 
                { 3,4 } 
        };
        int [] [] B = { 
                { 3,4- }, 
                { 5,6 } 
        }; 
        int [] [] = F { 
                { l, 2,3 },       
                { 1,8,6 }, 
                { 7,6, 9,7,5 } 
        }; 
        // array for adding 
        int [] [] = C new new  int [2] [2 ]; 
        
        for ( int I = 0; I <c.length; I ++ ) {
             for ( int J 0 =; J <c.length; J ++ ) { 
                C [I] [J]A = [I] [J] + B [I] [J]; 
            } 
            
        } 
        // print a two-dimensional array; outer loop line printing, the content of the print line cycle
 //         for (int I = 0; I <C. length; I ++) {
 //             for (int J = 0; J <c.length; J ++) {
 //                 of System.out.print (C [I] [J] + "\ T");
 //             }
 //             System.out.println ();
 //             
//         } 
        Print (the Add (A, B)); 
        
//         C [0] [0] = A [0] [0] + B [0] [0];
 / /         C [0] [. 1] = A [0] [. 1] + B [0] [. 1];
 //         C [. 1] [0] = A [. 1] [0] + B [. 1] [0] ;
 //         C [. 1] [. 1] = A [. 1] [. 1] + B [. 1] [. 1];
 //        System.out.println(c[0][0]+"\t"+c[0][1]);
//        System.out.println(c[1][0]+"\t"+c[1][1]);
    }
    
            

}

 

Guess you like

Origin www.cnblogs.com/ssxblog/p/11203365.html