我看过比较器和算法,但我无法理解它们。 java.util.Collections中的比较器事物。 所以我选择使用此:按降序排列数组?
//return an array in descending order, using set algorithm
public int[] descendSort()
{
int[] tempArray = new int[temps.length];
for (int i = temps.length-1; i <= 0; --i)
{
tempArray[i] = temps[i];
}
return tempArray;
}
我在我的客户端创建数组是这样的:
int[] temps1 = new int[]{45, 76, 12, 102, 107, 65, 43, 67, 81, 14};
我的输出最终是这样的:
The temperatures in descending order is: 0 0 0 0 0 0 0 0 0 0
WHY ????
在这里你可以看到如何使用比较器接口: http://stackoverflow.com/questio ns/7414299/sorting-int-array-in-descending-order – denisazevedo
@HovercraftFullOfEels我做了一个方法,它在手之前对数组排序,所以这不是问题。 – PatGreens