私はこのようなものを持っています:
Scanner in=new Scanner(System.in);
int rounds = 0;
while (rounds < 1 || rounds > 3) {
System.out.print("How many rounds? ");
if (in.hasNextInt()) {
rounds = in.nextInt();
} else {
System.out.println("Invalid input. Please try again.");
System.out.println();
}
// Clear buffer
}
System.out.print(rounds+" rounds.");
どうすればバッファをクリアできますか?
編集:私は以下を試しましたが、何らかの理由で機能しません:
while(in.hasNext())
in.next();