【发布时间】:2015-11-30 15:11:11
【问题描述】:
现在我有一个处理分数的项目。需要对分数进行排序,去掉最高和最低的分数,然后将中间的分数加在一起。我已经创建了数组,并完成了排序。我不知道如何降低最高和最低。任何帮助表示赞赏,谢谢!
public class Tester {
public static void main(String[] args) {
double[] fractions = {(6/7),(2/4),(3/4),(3/18),(1/8),(10/20),(2/6)};
}
public static void selectionSort (int... arr)
{
int i = 0, j = 0, smallest = 0;
int temp = 0;
for (i = 0;i<arr.length - 1;i++)
{
smallest = i;
for (j = 1; j<arr.length - 1; j++)
{
if (arr[j]<arr[smallest])
smallest = j;
}
temp = arr[smallest];
arr[smallest] = arr[i];
arr[i] = temp;
}
//Drop highest and lowest here
}
}
【问题讨论】:
-
即使您使用的是
double,您的排序方法也会使用int数组? -
创建另一个数组并将其从第二个元素复制到最后一个元素 - 1
-
我猜是的,它现在没有因为 int 或 double 而出现任何错误