所以基本上问题是当你在输入行号后按enter键时。在该场景中,会跳过nextline()添加读取器。nextLine();之前
String cont=读卡器。nextLine();
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) {
String end = "e";
int [][] seat = new int [12][20];
for (int rows = 0; rows<seat.length;rows++){
for (int cols = 0; cols<seat[0].length; cols++){
seat[rows][cols] = 0;
}
}
while (end!="q"){
System.out.println();
System.out.print("\t");
for (int cols = 0; cols<seat[0].length;cols++){
System.out.print(cols+1 + "\t");
}
System.out.println();
for (int rows = 0; rows<seat.length;rows++){
System.out.print(rows+1 + "\t");
for (int cols = 0; cols<seat[0].length; cols++){
System.out.print("[" + seat[rows][cols] + "]" + "\t");
}
System.out.print( rows+1 );
System.out.println();
}
System.out.println();
String h = "Cinema Screen";
System.out.println(String.format("%45s", h));
try{
System.out.println();
System.out.print("Which column is your desired seat in? ");
Scanner reader = new Scanner(System.in);
int column = reader.nextInt();
System.out.print("Which row is your desired seat in? ");
int row = reader.nextInt();
System.out.println();
if (seat[row-1][column-1] == 1){
System.out.print("This seat is already taken. ");
}
else if (seat[row-1][column-1] != 1){
seat[row-1][column-1] = 1;
System.out.print("\t");
}
System.out.println();
System.out.print("Would you like to continue? ");
reader.nextLine();
String cont = reader.nextLine();
char contin = cont.charAt(0);
if (contin == 'n' || contin == 'N'){
end = "q";
}
}
catch (InputMismatchException e){
System.out.println();
System.out.print("The input has to be a valid integer.");
}
catch (ArrayIndexOutOfBoundsException e){
System.out.println();
System.out.print("Please choose an integer representing an existing seat.");
}
}
}
}