매니저/JAVA1

JAVA1 Array 예제4 (임시저장)

cdprkr2077 2011. 12. 23. 20:40


// 다차우너 배열 - 2차원 배열

class ArrayEx4
{
 public static void main(String[] args)
 {
  // int m[][] = new int[3][2];
  // int m[][] = new int[][] { {10, 20 }, { 30, 40 }, { 50, 60 } };
  
  int m[][] = { {10, 20 }, { 30, 40 }, { 50, 60 } };

  /*
  for( int i = 0; i < m.length; i++ )     // 행  0 1 2
  {
   for( int j = 0; j < m[i].length; j++ )    // 열  0 1
   {
    System.out.print( "m[" + i + "][" + j + "] = " + m[i][j] + "\t" );
   }
   System.out.println();
  */

  /*
  for( int i = 0; i < m.length; i++ )     // 행  0 1 2
  {
   for( int j = m[i].length - 1; j >= 0; j-- )   // 열  1 0
   {
    System.out.print( "m[" + i + "][" + j + "] = " + m[i][j] + "\t" );
   }
   System.out.println();
   */

  for( int i = m.length - 1; i >= 0; i-- )     // 행  2 1 0
  {
   for( int j = m[i].length - 1; j >= 0; j-- )    // 열  1 0
   {
    System.out.print( "m[" + i + "][" + j + "] = " + m[i][j] + "\t" );
   }
   System.out.println();
  }
 }
}