【发布时间】:2014-12-12 08:14:19
【问题描述】:
为什么我会收到 Possible lossy conversion from double to int 错误,我该如何解决?
public class BinSearch {
public static void main(String [] args)
{
double set[] = {-3,10,5,24,45.3,10.5};
double l = set.length;
double i, j, first, temp;
System.out.print("Before it can be searched, this set of numbers must be sorted: ");
for (i = l-1; i>0; i--)
{
first=0;
for(j=1; j<=i; j++)
{
if(set[j] < set[first]) // location of error according to compiler
{
first = j;
}
temp = set[first];
set[first] = set[i];
set[i] = temp;
}
}
}
}
如您所见,我已经尝试在声明变量时将int 替换为靠近顶部的double,但它似乎不起作用。
【问题讨论】:
-
当您的
double(例如3.141)用于访问数组索引时,您认为会发生什么? -
说实话,我真的不知道:/。
标签: java int double type-conversion