2楼的方法很对,但是我直接定义一个新数组,然后把这个新数组赋给原数组是不是更好理解?
- class Demo
- {
- public static void main(String[] args)
- {
- int[][] arr ={{1,2,3,10},{4,5,6,11},{7,8,9,12},{13,14,15,16}};
- int x = arr[0].length;
- int y = arr.length;
- int[][] aft = new int[y][x];
- for (int i = 0;i < x;i++ )
- {
- for (int j = 0;j<y ;j++ )
- {
- aft[j][i] = arr[i][j];
- System.out.print(arr[j][i]);
- }
- System.out.println("");
- }
- arr = aft;
- }
- }
复制代码 |