728x90
public class ExerciseCh2_7 {
public static void transpose(int arr1[][],int arr2[][]) {
for(int i=0; i<arr1.length; i++) {
for(int j=0; j<arr1[0].length; j++) {
arr2[j][i] = arr1[i][j];
}
}
}
public static void main(String[] args) {
int [][] arr1 = {{1, 2, 3}, {4, 5, 6}};
for (int i=0; i<arr1.length; i++){
for (int j=0; j<arr1[0].length; j++)
System.out.print(arr1[i][j]);
System.out.println();
}System.out.println();
int [][] arr2 = new int[arr1[0].length][arr1.length];
transpose(arr1, arr2);
for (int i=0; i<arr2.length; i++){
for (int j=0; j<arr2[0].length; j++)
System.out.print(arr2[i][j]);
System.out.println();
}
}
}
반응형
'전.java' 카테고리의 다른 글
16진수를 10진수로 변환 (0) | 2021.01.28 |
---|---|
마방진(magic square) (0) | 2021.01.28 |
예외 발생 (NullPointerException) (0) | 2021.01.28 |
정수, 실수 나눗셈 (0) | 2021.01.28 |
문자 리터럴 (0) | 2021.01.28 |