出于某种原因,当我在eclipse上运行我的代码时,屏幕上没有任何显示内容。我不确定它是什么。我可以在控制台中键入输入,但这是关于它的。没有其他事情发生。谁能告诉我它可能是什么?谢谢。
import java.util.Scanner;
public class Test {
public static void main (String [] args) {
Scanner input = new Scanner (System.in);
Flight flight = new Flight (input.nextLine(), input.nextLine(), input.nextLine(), input.nextLine(), 0);
System.out.println("Creating first flight");
System.out.println("What is the name of the flight?");
String flightName = input.nextLine();
System.out.println("What is the destination of the flight?");
String destination = input.nextLine();
System.out.println("What is the departure time of the flight?");
String departureTime = input.nextLine();
System.out.println("What is the departure gate of the flight?");
String departureGate = input.nextLine();
boolean done = false;
while (!done) {
System.out.println("Now what would you like to do?");
System.out.print("1. Print out a flight's info");
System.out.print("2. Print out the number of flights through the static variable.");
System.out.print("3. Change the departure time of a flight.");
System.out.print("4. Change the departure gate of a flight.");
System.out.print("5. Exit");
int choice = input.nextInt();
switch (choice) {
case 1:
System.out.println("Which flight would you like to print the info of (1 or 2)?");
int selection = 0;
selection = input.nextInt();
if (selection == 1 || selection == 2) {
Flight.printFlight();
} else{
System.out.println("Invalid Option");
} break;
case 2:
System.out.println("This is the number of flights" + Flight.getNumFlights());
break;
case 3:
System.out.println("Which flight would you like to change the departure time of (1 or 2)?");
int selection2 = 0;
selection2 = input.nextInt();
if (selection2 == 1 || selection2 == 2){
System.out.println("What is the new departure time for flight " + (Flight.getNumFlights()-1));
String newDeptTime = input.nextLine();
Flight.changeDeptTime(newDeptTime);
} else{
System.out.println("Invalid Option");
} break;
case 4:
System.out.println("Which flight would you like to change the departure gate of?");
int selection3 = input.nextInt();
if (selection3 == 1 || selection3 == 2){
System.out.println("What is the new departure gate for flight " + Flight.getNumFlights());
String newDeptGate = input.nextLine();
Flight.changeDeptGate(newDeptGate);
} else {
System.out.println("Invalid option");
} break;
case 5:
done = true;
break;
default:
System.out.println("Invalid option");
break;
}
}
}
}
答案 0 :(得分:0)
它没有显示任何内容,因为它等待你在Flight类构造函数中输入你想要的字符 正如你在这里看到的那样
Flight flight = new Flight (input.nextLine(), input.nextLine(), input.nextLine(), input.nextLine(), 0);
执行在input.nextLine()
部分停止,直到您输入内容并按Enter键
PS:最好在输入部分之前放置一些System.out.printlns("输入值")类型的语句以向用户显示该做什么。这样做会阻止你制作你犯的这个错误