1 //将一个二维数组行和列元素互换.存到另一个二维数组
2 package test;
3
4 public class test1_8 {
5 public static int[][] huhuan(int[][] a) {
6 int[][] b = new int[3][3];
7 for (int i = 0; i < a.length; ++i) {
8 for (int j = 0; j < a[i].length; ++j) {
9 b[j][i] = a[i][j];
10 }
11 }
12 /*
13 * System.out.println("交换后的数组为:"); for (int j = 0; j < b.length; ++j) { for (int
14 * i = 0; i < b[j].length; ++i) { System.out.print(b[j][i] + " "); }
15 * System.out.println(); }
16 */
17 return b;
18 }
19
20 public static void main(String[] args) {
21 // TODO Auto-generated method stub
22 int[][] a = new int[3][3];
23 for (int i = 0; i < a.length; ++i) {
24 for (int j = 0; j < a[i].length; ++j) {
25 a[i][j] = (int) (Math.random() * 100);
26 }
27 }
28 System.out.println("随机产生的一个二维数组为:");
29 for (int i = 0; i < a.length; ++i) {
30 for (int j = 0; j < a[i].length; ++j) {
31 System.out.print(a[i][j] + " ");
32 }
33 System.out.println();
34 }
35 int[][] b = huhuan(a);
36 System.out.println("交换后的数组为:");
37 for (int j = 0; j < b.length; ++j) {
38 for (int i = 0; i < b[j].length; ++i) {
39 System.out.print(b[j][i] + " ");
40 }
41 System.out.println();
42 }
43 }
44
45 }
标签:java,int,System,++,length,数组,println,返回值,out
来源: https://www.cnblogs.com/dss-99/p/14016765.html