java中如何返回一个数组?
展开全部
public class xiti5_5 {
public static void Printf(int a[][]) {
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
public static int[][] FangFa(int a[][]) {
int b[][] = new int[a[0].length][a.length];
for (int i = 0; i < a[0].length; i++) {
for (int j = 0; j < a.length; j++)
b[i][j] = a[j][i];
}
return b;
}
public static void main(String args[]) {
int a[][] = { { 1, 2, 3 }, { 4, 5, 6 } };
Printf(a);
Printf(FangFa(a));
}
}
-----------------
1 2 3
4 5 6
1 4
2 5
3 6
public static void Printf(int a[][]) {
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
public static int[][] FangFa(int a[][]) {
int b[][] = new int[a[0].length][a.length];
for (int i = 0; i < a[0].length; i++) {
for (int j = 0; j < a.length; j++)
b[i][j] = a[j][i];
}
return b;
}
public static void main(String args[]) {
int a[][] = { { 1, 2, 3 }, { 4, 5, 6 } };
Printf(a);
Printf(FangFa(a));
}
}
-----------------
1 2 3
4 5 6
1 4
2 5
3 6
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |