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]);
}
}
By the code above I am sorting the columns of an array and then printing them. But I don't understand why the ascending order sorted elements are printed in descending order. Someone please check it. Thanks!!
Following is the output: This is the input matrix 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
The column matrix is 25.0 25.0 25.0 25.0
0 0 0 0
The sorted column matrix is0 25.0 25.0 25.0 25.0
The column matrix is 10.0 5.0 23.0 89.0
2 1 2 3
The sorted column matrix is1 89.0 23.0 10.0 5.0
The column matrix is 24.0 23.0 6.0 8.0
3 1 2 3
The sorted column matrix is2 24.0 23.0 8.0 6.0
for (int j = i; j < arraytosort.length; j++) {
从i
开始第二个循环
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.