【发布时间】:2018-10-28 19:00:32
【问题描述】:
我写了一个使用while循环的简单猜谜游戏。 如果用户输入任何首字母为“y”的单词,游戏将重新运行,但如果用户输入任何其他单词,游戏将退出并给出报告。
public static void loopcalc(Scanner console) {
int totalRounds = 0, totalGuesses = 0, best = 1000000;
boolean want = true;
while (want = true) {
int eachguess = playOneGame(console);
totalRounds++;
totalGuesses += eachguess;
System.out.println("Do you want to play again?");
String input = console.next();
if (input.toLowerCase().charAt(0) == 'y') {
want = true;
} else {
want = false;
}
best = Math.min(eachguess, best);
}
report(console, totalGuesses, totalRounds, best);
}
对不起,我不知道如何正确输入代码。
【问题讨论】:
标签: java loops while-loop