哪种情况会使用nextLine创建nosuchelementexception?

问题描述

nextLine()的文档说它可以抛出nosuchelementexception。但是,如下面的代码所示,使用nextLine()获取扫描程序的输入时,不会引发nosuchelementexception。唯一发生的事情是通过按两次两次Enter键来结束程序。我向在线系统提交了相同的代码以进行评估,系统还说该代码抛出了nosuchelementexception

什么样的输入会产生nosuchelementexception

String input = "";
Scanner sc = new Scanner(System.in);

input += sc.nextLine() + " ";
input += sc.nextLine() + " ";

System.out.println(input);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)