我无法在运行时filmType
中输入字符串。一旦到达要求filmType
的行,程序便结束。
public class Main {
public static void main(String[] args) {
Scanner In = new Scanner(System.in);
System.out.println("enter film name");
String s = In.nextLine();
System.out.println("enter Budget");
int Budget=In.nextInt();
System.out.println("enter running time");
double running = In.nextDouble();
System.out.println("enter film Type");
String filmType = In.nextLine();
}
}
答案 0 :(得分:0)
您的代码存在问题是使用nextInt
和nextDouble
。
这些方法未考虑您在特定问题输入的行中插入的换行符\n
(输入)。该换行符将转到您下次调用nextLine
时,并将立即为该变量分配一个空行。
例如,您可以将代码更改为:
Scanner In = new Scanner(System.in);
System.out.println("enter film name");
String s = In.nextLine();
System.out.println("enter Budget");
String BudgetString = In.nextLine();
int budget = Integer.parseInteger(BudgetString); // with proper numberFormatException handling
System.out.println("enter running time");
String runningString = In.nextLine();
double running = Double.parseDouble(runningString); // with proper numberFormatException handling
System.out.println("enter film Type");
String filmType = In.nextLine();