我正在尝试获取特定人员前面的患者人数。我如何从for循环返回int?它始终返回0。从for循环返回int
public int pAhead(String name) {
Patient p;
int patientsAhead = 0;
for(int i= 0; i < list.size(); i++)
{
p = list.get(i); //get each object from array
String n = p.getName();
if(name.equalsIgnoreCase(n))
{
//if name passed is equal to object getName, than get the index of that object
patientsAhead = list.indexOf(p);
}
}
return patientsAhead;
}
你确定0是错误的结果吗? – wvdz 2014-10-16 11:21:57
你在哪里声明了'list'?因为它没有被传递到代码中的函数u posted – 4rlekin 2014-10-16 11:22:03
将if语句的真实部分更改为'return i;'。 – munyul 2014-10-16 11:22:21