下面的方法返回所有在作爲參數傳遞的範圍內具有馬力的所有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-找到一個數組列表的長度) –