Java 空白扫描仪下一行使用输入,如果没有输入,则跳过该行
问题:使用扫描仪(sc)从用户处获取输入,如果我没有使用空白的sc.nextLine(),则将跳过上一行。如果我使用这个空白火,变量永远不会被收集起来供以后使用Java 空白扫描仪下一行使用输入,如果没有输入,则跳过该行,java,Java,问题:使用扫描仪(sc)从用户处获取输入,如果我没有使用空白的sc.nextLine(),则将跳过上一行。如果我使用这个空白火,变量永远不会被收集起来供以后使用 System.out.println("Please enter the Airline name: "); String airName = sc.nextLine(); sc.nextLine(); <--------- System.out.println("Please enter the Air
System.out.println("Please enter the Airline name: ");
String airName = sc.nextLine();
sc.nextLine(); <---------
System.out.println("Please enter the Airline code: ");
String airCode = sc.nextLine();
System.out.println("Please enter the Delta Aircraft: ");
String airCraft = sc.nextLine();
System.out.println("Please enter the first class seat capacity: ");
int firstClass = sc.nextInt();
System.out.println("Please enter the business class seat capacity: ");
int busiClass = sc.nextInt();
System.out.println("Please enter the economy class seat capacity: ");
int econClass = sc.nextInt();
System.out.println("Airline name: " + airName);
System.out.println("Airline code: " + airCode);
System.out.println("Delta Aircraft: " + airCraft);
//Splitting the first word from the rest of the string
String arr[] = airCraft.split(" ", 2);
String firstWord = arr[0];
System.out.println(firstWord + " first class seat capacity: " + firstClass);
System.out.println(firstWord + " business class seat capacity: " + busiClass);
System.out.println(firstWord + " economy class seat capacity: " + econClass);
//Airline object
A8AirlineAircraftData airline = new A8AirlineAircraftData(airName, airCode, airCraft, firstClass, busiClass, econClass);
System.out.println(airName + " successfully added. Press Enter to continue.");
sc.nextLine();//Press Enter to continue
sc.nextLine();
//A8MainMenu.mainMenu(sc); //return to main menu after Enter.
return airline;
在我开始扫描之前,我不得不放置一个空白的sc.nextLine
sc.nextLine();
System.out.println("Please enter the Airline name:");
String airName = sc.nextLine();
您可能必须引用此线程。我试过,我试过用空白的火。
sc.nextLine();
System.out.println("Please enter the Airline name:");
String airName = sc.nextLine();