我的java代码没有错误,但是为什么赢了';它不跑吗?
出于某种原因,当我在eclipse上运行代码时,屏幕上没有显示出应有的内容。我不知道是什么。我可以在控制台中键入输入,但仅此而已。没有别的事情发生。有人能告诉我可能是什么吗?谢谢我的java代码没有错误,但是为什么赢了';它不跑吗?,java,Java,出于某种原因,当我在eclipse上运行代码时,屏幕上没有显示出应有的内容。我不知道是什么。我可以在控制台中键入输入,但仅此而已。没有别的事情发生。有人能告诉我可能是什么吗?谢谢 import java.util.Scanner; public class Test { public static void main (String [] args) { Scanner input = new Scanner (System.in); Flight flight = new
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;
}
}
}
}
它没有显示任何内容,因为它正在等待您在Flight class构造函数中输入所需的字符。
正如你在这里看到的
Flight flight = new Flight (input.nextLine(), input.nextLine(), input.nextLine(), input.nextLine(), 0);
执行在input.nextLine()
parts处停止,直到输入内容并按enter键
附言:最好放置一些
System.out.println(“输入值”)
在输入部分之前的一种语句,用于向用户显示要执行的操作。有趣的是,这样做可以防止您犯此错误在调试中插入断点并运行它,然后逐步检查代码并查看其中断位置。即使为航班
,对吗?除非您输入一些文本,否则不会显示任何内容,因为您在构建航班时要求使用扫描仪在标准输入上输入。哎呀……我的眼睛完全错过了……谢谢everyone@user7087153这就是调试器应该能够在几秒钟内告诉您的。