简体   繁体   English

升序排序数组是按降序打印的吗?

[英]Ascending order Sorted array is getting printed in descending order?

   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 以下是输出:这是输入矩阵arraydc

0.0 0.0 0.0 0.0 0.0 0.0
25.0 10.0 24.0 25.0 10.0 24.0
25.0 5.0 23.0 25.0 5.0 23.0
25.0 23.0 6.0 25.0 23.0 6.0
25.0 89.0 8.0 25.0 89.0 8.0


The column matrix is 25.0 25.0 25.0 25.0 列矩阵为25.0 25.0 25.0 25.0


0 0 0 0 0 0 0 0


The sorted column matrix is0 25.0 25.0 25.0 25.0 排序的列矩阵为0 25.0 25.0 25.0 25.0


The column matrix is 10.0 5.0 23.0 89.0 列矩阵为10.0 5.0 23.0 89.0


2 1 2 3 2 1 2 3


The sorted column matrix is1 89.0 23.0 10.0 5.0 排序的列矩阵是1 89.0 23.0 10.0 5.0


The column matrix is 24.0 23.0 6.0 8.0 列矩阵为24.0 23.0 6.0 8.0


3 1 2 3 3 1 2 3


The sorted column matrix is2 24.0 23.0 8.0 6.0 排序的列矩阵是2 24.0 23.0 8.0 6.0


for (int j = i; j < arraytosort.length; j++) {

i开始第二个循环

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM