我遇到了一个我不明白的问题。 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/