下面的方法返回所有在作为参数传递的范围内具有马力的所有Lamborghini对象的数组。当我尝试在Lamborghini.length编译错误时找不到符号 - 可变长度。不是ArrayList的长度部分?Java ArrayList长度错误
public Lamborghini[] getCarsWithHorsepowerRange(double lowHP, double highHP)
{
int horsePower = 0;
for(int i = 0; i < Lamborghini.length; i++)
{
if(Lamborghini[i] != null)
{
if((Lamborghini[i].getHorsePower() >= lowHP) &&
((Lamborghini[i].getHorsePower() <= highHP)))
{
horsePower++;
}
}
您能显示'Lamborghini'的声明吗? – resueman
.size(),并通过.get(i)获得索引 – Steven
[如何查找数组列表的长度?]的可能重复(http://stackoverflow.com/questions/9652732/how-to-找到一个数组列表的长度) –