【发布时间】:2013-05-23 16:19:44
【问题描述】:
我想对这个二维数组进行排序,使其输出如下内容:
1 2 3
4 5 6
7 8 9
还告诉我它做了多少动作来重新排列。谢谢你的分配!
到目前为止,这是我的代码:
public static void main(String[] args) {
int firstArray [][] ={{3,8,5},{1,6,9},{2,4,7}};
System.out.println("This is array to sort:");
displayArray(firstArray);
}
public static void displayArray(int x[][]) {
for (int row=0;row<x.length;row++) {
for(int column = 0;column<x[row].length; column++) {
System.out.print(x[row][column]+"\t");
}
System.out.println();
}
}
【问题讨论】:
-
这段代码只会打印数组。给我们一个您尝试过或遇到问题的代码。
-
这可以在两个
for-loops现在想想! -
Tdorno 先生,请您帮帮我,这是我的家庭作业,老师只教我们基础知识。我读了很多书,想不通。拜托,我会很高兴的!
标签: java arrays algorithm sorting