gpt4 book ai didi

java - 需要返回单吗? - 编码新手

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:54:18 26 4
gpt4 key购买 nike

想法是拍卖中的不同批处理。我知道我需要一个类型为“Lot”的返回语句,但我不确定那是什么。这是我的代码。

public Lot getLot(int lotNumber)
{
int index = 0;
boolean found = false;

while(index < lots.size() && !found) {
Lot selectedLot = lots.get(index);
if(selectedLot.getNumber() == lotNumber) {
found = true;

}
else {
index++;

}

}

if(!found) {
found = false;

}

}

最佳答案

你可以做的是与此类似的事情,如果找到匹配,它将返回匹配的 selectedLot,如果没有找到匹配,它将返回 null:

public Lot getLot(int lotNumber) {
int index = 0;

while(index < lots.size()) {
Lot selectedLot = lots.get(index);

if (selectedLot.getNumber() == lotNumber) {
return selectedLot;
} else {
index++;
}
}

return null;
}

关于java - 需要返回单吗? - 编码新手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34169131/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com