我有这种方法,它使用一个 for each 循环,其中有一个 if 语句
public static Apartment getApartment(String aNumber)
//for loop to iterate through the list of apartments
{
for (Apartment x : listOfApartments)
{
// Variable to hold the value of returned apartment
if (x.getApartmentNo().equalsIgnoreCase(aNumber))
{ Apartment chosen = x;
}
else
{JOptionPane.showMessageDialog(null, "Apartment not found");
}
}
return chosen;
}
我收到未找到符号选择的错误。我想我在错误的地方声明了变量。有什么帮助吗?注意:这是一个接受 String 并返回 Object Apartment 的方法。