此段導致錯誤,提示找不到符號 - 方法 itemsSold (int)
int total = itemsSold(0);
int max = itemsSold(0);
int min = itemsSold(0);
我假設它與那些線
public class Payroll
{
private int[] itemsSold;
public Payroll(int[] i)
{
itemsSold = i;
}
public static void ingWords (String [] w)
{
for(String str: w)
{
if(str.substring(str.length()-3).equals("ing"))
{
System.out.println(str);
}
}
}
public double computeBonusThreshold()
{
int total = itemsSold(0);
int max = itemsSold(0);
int min = itemsSold(0);
for(int i= 1; i < itemsSold.length; i )
{
total = itemsSold[i];
if(itemsSold[i] > max)
{
max = itemsSold[i];
}
if(itemsSold[i] < min)
{
min = itemsSold[i];
}
}
return (double)(total-max-min)/(itemsSold.length-2);
}
}
和測驗人員類以防它以某種方式導致問題
public class TestPayroll
{
public static void main(String [] args)
{
String[] words = new String[] {"rolling", "hello", "watching", "goodbye", "hiking"};
int[] sold = new int[] {48,50,37,62,38,70,55,37,64,60};
Payroll.ingWords(words);
Payroll company = new Payroll (sold);
double threshold = company.computeBonusThreshold();
System.out.println(threshold);
}
}
uj5u.com熱心網友回復:
當 itemsSold 后面有括號時,java 認為您正在嘗試呼叫名為 itemsSold的方法。
但是,您的 itemsSold 是一個陣列。要訪問陣列元素,您需要使用方括號。
int total = itemsSold[0];
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/433003.html
上一篇:Java陣列填充
