ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 배열출력
    JAVA 2020. 5. 6. 18:45
    package test01;
    import java.util.Arrays;
    public class test04 {
          public static  int [][] copy(int [][] b) {
                  int [][] c;
                  c = new int[b.length][];
                  for(int i=0; i<b.length; i++) c[i] = new int[b[i].length];
                  for(int i=0; i<b.length; i++)
                   for(int j=0; j<b[i].length; j++)
                    c[i][j] = b[i][j];
                  return c;
                 }
          
          public static void main(String[] args) {
                // TODO Auto-generated method stub
                int[] c = {56,87,96,59,87,48,56,33,65,78};
                int[] d= c.clone();
                System.out.println(Arrays.toString(c));
                System.out.println(Arrays.toString(d));
                
                int [][] a = {{1,2,3},{4,5,6},{7,8,9}};
                int [][] b = copy(a);
                //copy() => clone()을 메소드로 만든경우
                
                System.out.println(Arrays.deepToString(a));
                System.out.println(Arrays.deepToString(b));
                
                //b[0][0]=100;
                for(int i=0; i<b.length; i++)
                      for(int j=0; j<b[i].length; j++)
                            System.out.printf("%d %d    ",a[i][j], b[i][j]);
          }
    }

    'JAVA' 카테고리의 다른 글

    메소드  (0) 2020.05.06
    상속 extends  (0) 2020.05.06
    전달인수가 정해지지 않은경우 사용법  (0) 2020.04.22
    오버로딩  (0) 2020.04.22
    달력 캘린더  (0) 2020.04.22

    댓글

Designed by Tistory.