【发布时间】:2014-04-11 15:19:26
【问题描述】:
public void sortcolumn(double[] arraytosort) {
a = new int[5];
for (int i = 1; i < arraytosort.length; i++) {
for (int j = 1; j < arraytosort.length; j++) {
if ((arraytosort[i]) > (arraytosort[j])) {
tempVar = arraytosort[j];
arraytosort[j] = arraytosort[i];
arraytosort[i] = tempVar;
a[i] = j;
}
}
System.out.println( a[i]);
}
}
public void decisionvalue(double[][] arraydc){
arrtemp = new double[arraydc.length];
for(int i =0; i<arraydc[0].length;i++){
System.out.println("The column matrix is");
for(int j =1; j<arraydc.length;j++){
arrtemp[j] = arraydc[j][i];
System.out.println(arrtemp[j]);
}
sortcolumn(arrtemp);
System.out.println("The sorted column matrix is" +i);
for(int k =1; k<arraydc.length; k++)
System.out.println(arrtemp[k]);
}
}
通过上面的代码,我对数组的列进行排序,然后打印它们。但我不明白为什么升序排序的元素以降序打印。有人请检查一下。谢谢!!
以下是输出: 这是输入矩阵arraydc
0.0 0.0 0.0
25.0 10.0 24.0
25.0 5.0 23.0
25.0 23.0 6.0
25.0 89.0 8.0
列矩阵是 25.0 25.0 25.0 25.0
0 0 0 0
排好序的列矩阵为0 25.0 25.0 25.0 25.0
列矩阵是 10.0 5.0 23.0 89.0
2 1 2 3
排好序的列矩阵为1 89.0 23.0 10.0 5.0
列矩阵是 24.0 23.0 6.0 8.0
3 1 2 3
排好序的列矩阵是2 24.0 23.0 8.0 6.0
【问题讨论】:
-
你用什么来调用这些函数?
-
MattR 我用输出中显示的矩阵调用这些函数。请看那个。 (arraydc 矩阵)