2015-03-08 52 views
0

所以这是我的程序链接到驱动程序。我遇到了可能有损转换的问题,并且我了解我拥有它的位置,但我不知道如何解决此问题。我需要重新安排一个Double[] array = new Double[20],通过从最低到最高排列数字,如下所示。我如何正确执行此操作,而不对我的程序进行重大更改?Java可能的有损转换双重转换为Int

public void insert (double val){ 
    if(count < 20){ 
    if(val >= 1 || val <= 10){ 
     array[count] = val; 
     count++; 
    } 
    }         
} 

double min; 
double max; 
double tmp; 

for(min = count - 1; min > 0; min--){ 
    max = 0; 
    for(int i = 1; i <= min; i++){  // Error here because of the min value 
     if(val[i] > val[max]){   // Error here because of the max value 
     max = i; 
     } 
    } 
    if(max != min){ 
     tmp = val[max];     // Error here because of the max value 
     val[max] = val[min];   // Error here because of the min value 
     val[min] = tmp;     // Error here because of the min value 
    } 
} 
+0

你的循环似乎没有在一个方法中,也是'list'(或者它是'array')定义的地方吗? – 2015-03-08 22:19:22

+0

看起来他已经定义了,他只是想对它进行排序,但我看到了你的要点xD – 2015-03-08 22:23:55

回答

1

minmax变量不应该是双打。它们是数组索引,因此它们在实践中受0和Integer.MAX_VALUE限制。

将它们更改为int