import java.util.*;
public class MovieInfo
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the name of the film");
String name = in.nextLine();
System.out.println("Enter the film budget");
int bud = in.nextInt();
System.out.println("Enter the running time");
double time = in.nextDouble();
System.out.println("Enter the film production house");
String s1 = in.nextLine();
System.out.println("Film being screened : "+name);
System.out.println("Budget "+bud+" cores");
System.out.println("Running time "+time+" hours");
System.out.println("Production : "+s1);
}
}
在上述程序的输出中,它不接受字符串 s1 的输入。 我如何解决它? 任何帮助将不胜感激。
最佳答案
尝试添加以下附加行:
in.nextLine();
该行之后:
double time = in.nextDouble();
使用换行符(当您使用Enter键接受输入double
时创建),该字符未通过使用.nextDouble()
调用。
请引用链接that question ,由 LenosV 提供,以获取有关 Scanner
行为原因的详细信息。
关于java - 为什么我们无法在下面的代码中输入字符串 s1 ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49530164/