【发布时间】:2021-10-12 15:52:12
【问题描述】:
我不知道如何存储第一个队列中的项目,保存它们然后重新添加它们
现在它通过一次然后队列是空的
我知道概念只是不知道语法
尝试创建第二个队列并在队列为空时重新添加玩家,但没有成功
Queue<Baseball_PlayerItem> players = getplayers();
int ct = 0;int outCt = 0;
boolean game = true;
for (Baseball_PlayerItem item : players) {
while (game) {
do {
Random rand = new Random();
double rand2 = rand.nextDouble();
item = players.remove();
if (item.getBatAvg() > rand2) {
System.out.printf("\nHit Perc: %s player: %s", rand2, item.getBatAvg());
ct++;
if (ct >= 3) {
System.out.printf("\nAnother home run total: %s", ct);
}
} else if (item.getBatAvg() < rand2) {
System.out.printf("\nThats Miss");
outCt++;
if (outCt == 3) {
System.out.printf("\nThree outs game over :( Outs: %s",outCt);
}else if (players.isEmpty()) {
System.out.printf("\nAll done");
checkGameStatus();
game = false;
}
}
} while (game = true);
}
}
}```Okay game on inning: 1
Thats Miss
Thats Miss
Thats Miss
Three outs game over :( Outs: 3
Thats Miss
Thats Miss
Thats Miss
Thats Miss
Hit Perc: 0.12601973051909088 player: 0.323
Another home run total: 8
Thats Miss
All done
Would you like to start the game (Y/N)---->y
Exception in thread "main" java.util.NoSuchElementException
【问题讨论】:
标签: java database list linked-list queue