2 回答

TA贡献1900条经验 获得超5个赞
假设你想永远循环,你需要检查容量不足和过剩
do {
oystersIn=0;
System.out.println("How many oysters are coming in?");
oystersIn = input.nextInt();
if (oystersIn + currentCapacity >= 500) {
System.out.println("Sorry full - waiting for some one to leave");
continue;
}
if (oystersIn + currentCapacity < 0) {
System.out.println("Can't go negative");
continue;
}
currentCapacity += oystersIn;
System.out.println("Now there are " + currentCapacity + " oysters in the bar");
}
while (true);

TA贡献1851条经验 获得超5个赞
我建议你:-
1)运行另一个 do while 循环,它接受负输入。2)如果你想在牡蛎不再可用的情况下重新运行程序并使用“break”,请将两个循环置于无限循环中;从无限循环中出来。 希望这可以帮助
添加回答
举报