public class ArrayOrderBy {
public static void main(String[] args) {
int array[][] = new int[][] {
{ 3, 34, 68, 85, 9, 12, 78 },
{ 7, 72, 83, 57, 56, 0, 1 },
{ 12, 34, 37, 32, 5, 945, 23 },
{ 91, 10, 3, 2354, 7, 34, 18 },
{ 12, 45, 145, 26, 6, 98, 33 },
{ 47, 45, 84, 24, 45, 23, 657 },
{ 12, 34, 34, 343, 34, 235, 778 },
{ 12, 34, 98, 4, 56, 54, 12, 586 },
{ 45, 78, 234, 78, 37895, 456, 8783 } };// 要排序的数组
orderby(array,4);
}
/*
* 第一个参数为要排序的数组
* 第二个参数为要排序的那一列
*/
private static void orderby(int arr[][],int i){
for (int b = 0; b < arr.length; b++) {
for (int j = 0, a=arr.length; j < a-b-1; j++) {
if(arr[j][i]>arr[j+1][i]){
for (int k = 0; k < arr[0].length; k++) {
int temp=arr[j+1][k];
arr[j+1][k]=arr[j][k];
arr[j][k]=temp;
}
}
}
}
for (int j = 0; j < arr.length; j++) {
for (int j2 = 0; j2 < arr[0].length; j2++) {
System.out.print(arr[j][j2]+" ");
}
System.out.println();
}
}
}
public static void main(String[] args) {
int array[][] = new int[][] {
{ 3, 34, 68, 85, 9, 12, 78 },
{ 7, 72, 83, 57, 56, 0, 1 },
{ 12, 34, 37, 32, 5, 945, 23 },
{ 91, 10, 3, 2354, 7, 34, 18 },
{ 12, 45, 145, 26, 6, 98, 33 },
{ 47, 45, 84, 24, 45, 23, 657 },
{ 12, 34, 34, 343, 34, 235, 778 },
{ 12, 34, 98, 4, 56, 54, 12, 586 },
{ 45, 78, 234, 78, 37895, 456, 8783 } };// 要排序的数组
orderby(array,4);
}
/*
* 第一个参数为要排序的数组
* 第二个参数为要排序的那一列
*/
private static void orderby(int arr[][],int i){
for (int b = 0; b < arr.length; b++) {
for (int j = 0, a=arr.length; j < a-b-1; j++) {
if(arr[j][i]>arr[j+1][i]){
for (int k = 0; k < arr[0].length; k++) {
int temp=arr[j+1][k];
arr[j+1][k]=arr[j][k];
arr[j][k]=temp;
}
}
}
}
for (int j = 0; j < arr.length; j++) {
for (int j2 = 0; j2 < arr[0].length; j2++) {
System.out.print(arr[j][j2]+" ");
}
System.out.println();
}
}
}