背对背扫描仪尝试提供异常资源

时间:2018-07-01 18:43:16

标签: java java.util.scanner

导入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)

有人可以帮助解决这种情况下的问题吗?

0 个答案:

没有答案