Arrays (Cont.)


Two examples of multi-dimensional arrays are given next:

MultiArray1.java (a multi-dimensional array)
01public class MultiArray1 {
02  public static void main( String[ ] args ) {
03    int[ ][ ]  mArray = new int[5][5];
04    for ( int i = 0; i < 5; i++ )
05      for ( int j = 0; j < 5; j++ )
06        mArray[i][j] = i*5 + j;
07    System.out.println( mArray[ Integer.parseInt( args[0] ) ]
08                              [ Integer.parseInt( args[1] ) ] );
09  }
10}
shell> java MultiArray1    

Output:           Result:

MultiArray2.java (another multi-dimensional array)
01public class MultiArray2 {
02  public static void main( String[ ] args ) {
03    int[ ][ ]  mArray = { {  012 },
04                          345 },
05                          678 },
06                          9, 10, 11 },
07                          { 12, 13, 14 } };
08    System.out.println( mArray[ Integer.parseInt( args[0] ) ]
09                              [ Integer.parseInt( args[1] ) ] );
10  }
11}
shell> java MultiArray2    

Output:           Result:




      I am a nobody, nobody is perfect, therefore I am perfect.