导入java.util.Scanner;
公共课程测试{
public static void main(String[] args)
{
try(Scanner sc = new Scanner(System.in))
{
System.out.println("Please enter");
System.out.println(sc.nextLine());
}
try(Scanner sc1 = new Scanner(System.in))
{
System.out.println("Please enter");
System.out.println(sc1.nextLine());
}
}
}
当我运行上面的代码时,出现以下错误:
Please enter
jhj ghuh
jhj ghuh
Exception in thread "main" Please enter
java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at Test.main(Test.java:16)
有人可以帮助解决这种情况下的问题吗?