Это ваш обновленный ответ.
public static void loopcalc(Scanner console) {
int totalRounds = 0, totalGuesses = 0, best = 1000000;
boolean want = true;
while (want) {
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);
}
Вы также можете попробовать следующий подход и избавиться от переменной want:
public static void loopcalc(Scanner console) {
int totalRounds = 0, totalGuesses = 0, best = 1000000;
boolean want = true;
while (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) == 'n') {
break;
}
best = Math.min(eachguess, best);
}
report(console, totalGuesses, totalRounds, best);
}