我正在尝试执行以下操作:
一种将猫的 ArrayList 中所有猫的腿合计的方法。
但是,我似乎无法将数组中猫腿的总数相加,或将其显示在控制台上。
public static int getNumOfLegs()
{
return numOfLegs;
}
public void setNumOfLegs(int numOfLegs)
{
this.numOfLegs = numOfLegs;
}
public static int totalNumOfLegs(ArrayList<Cat> catList)
{
int total = 0;
for (Cat c: catList)
{
total = total + getNumOfLegs();
}
return total;
}
非常感激。