java |字符串类型

标签 java string

我遇到了一个我不明白的问题。 nextLine() 应该用于句子,对吗?

System.out.println("Enter film's name");
a = scan.nextLine();
System.out.println("What number did the film released?");
b = scan.nextInt();
System.out.println("Who's the director?");
c = scan.nextLine();
System.out.println("How long is the film in minutes?");
d = scan.nextInt();
System.out.println("Have you seen the movie? Yes/No?");
e = scan.next();
System.out.println("Mark for the film?");
f = scan.nextDouble();

它一直正确运行,直到发布日期,然后它同时显示“谁是导演”和“这部电影多长”,并且无法正常工作。

如何使用 nextLine(); 以及为什么它对我不起作用?

最佳答案

缓冲区已满,每次连续调用后都会重置您的扫描仪。扫描.重置(); 。原因是之前的字符被缓存在输入流中。

关于 java |字符串类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42486506/

相关文章:

java - 如何在 Java 中不使用内置方法 .endsWith() 实现 String.endsWith()

python - 如何围绕数字拆分字符串?

ruby-on-rails - 定义一个 :class_name with a string or a symbol in Rails 3

java - 从相对路径读取/写入文件时出现问题

java - 带有 struts 标签的输出参数化 bean 属性

c++ - 删除缓冲区溢出 []

string - 查找包含另一个字符串的某些变位词作为子序列的字符串的子字符串数

java - Apache Camel 如何获取输入的 xml 负载大小?

验证全名的 Java 正则表达式只允许空格和字母

java - Spring Data、EclipseLink 和 SimpleLoadTimeWeaver;由不同 ClassLoader 加载的域类