public void humanPlay()
{
if (player1.equalsIgnoreCase("human"))
System.out.println("It is player 1's turn.");
else
System.out.println("It is player 2's turn.");
System.out.println("Player 1 score: " + player1Score);
System.out.print("Player 2 score: " + player2Score);
String eitherOr;
do {
eitherOr= input.nextLine();
humanRoll();
} while (eitherOr.isEmpty());
if (!eitherOr.isEmpty())
humanHold();
}
これが全体の方法です。私が修正しようとしているのはこれだけです。
String eitherOr;
do {
eitherOr= input.nextLine();
humanRoll();
} while (eitherOr.isEmpty());
入力を複数回受け入れる必要があるため、何が起こるかを判断するために毎回入力が必要です。そのため、Do Whileループが好きですが、少なくとも1回に1回初期化されるため、必要以上に余分なロールが発生します。
私はこの方法でそれをやろうとしました、そしてこの方法のさまざまなバリエーション:
String eitherOr = input.nextLine();
while(eitherOr.isEmpty());
humanRoll();
入力を再度要求しないため、これは機能しません。input.nextline();を入れようとすると whileループに入ると、「etherOr」は初期化されていないと表示されます。入力を入力したときに初期化しても、コマンドラインは空白のままなので、入力には何の影響もありません。