所以,我有一个循环,它使用扫描仪输入 3 个单独的用户输入,2 个整数和一个字符串。整数工作得很好,但字符串输入不起作用。它跳过了 String 的 iput,然后再次循环请求 int。
for(int e = 10; e > 5; e++)
{
System.out.println("Enter the Y coordinate of your guess. The upper left corner is 0, and the lower left is 7");
int guessY = inputDevice.nextInt();
System.out.println("Enter the X coordinate of your guess. The upper left corner is 0, and the upper right is 7");
int guessX = inputDevice.nextInt();
display[guessX][guessY] = map[guessX][guessY];
for(int j = 0; j < 8; j++)
{
for(int t = 0; t < 8; t++)
{
System.out.print(display[j][t] + " ");
}
System.out.println();
}
System.out.println("Enter go when you are ready to make another move.");
System.out.println("Enter quit to give up");
String cont = inputDevice.nextLine();
if(cont.equalsIgnoreCase("quit"))
{
System.out.println("Weenie.");
System.exit(0);
} else if(cont.equalsIgnoreCase("go")) {
for(int i = 0; i < 100; i++)
System.out.println("\b");
}
if(map[guessX][guessY] == '0')
{
if(map[guessX - 1][guessY - 1] == '0')
display[guessX - 1][guessY - 1] = map[guessX - 1][guessY - 1];
if(map[guessX - 1][guessY + 0] == '0')
display[guessX - 1][guessY + 0] = map[guessX - 1][guessY + 0];
if(map[guessX - 1][guessY + 1] == '0')
display[guessX - 1][guessY + 1] = map[guessX - 1][guessY + 1];
if(map[guessX + 0][guessY - 1] == '0')
display[guessX + 0][guessY - 1] = map[guessX + 0][guessY - 1];
if(map[guessX + 0][guessY + 1] == '0')
display[guessX + 0][guessY + 1] = map[guessX + 0][guessY + 1];
if(map[guessX + 1][guessY - 1] == '0')
display[guessX + 1][guessY - 1] = map[guessX + 1][guessY - 1];
if(map[guessX + 1][guessY + 0] == '0')
display[guessX + 1][guessY + 0] = map[guessX + 1][guessY + 0];
if(map[guessX + 1][guessY + 1] == '0')
display[guessX + 1][guessY + 1] = map[guessX + 1][guessY + 1];
}
if(display[guessX][guessY] == 'M')
{
System.out.println("You hit a mine");
System.out.println("Game over.");
System.exit(0);
}
}