首页 > 解决方案 > 通过 ideone 运行时,扫描仪上的 NoSuchElementException 有什么问题?

问题描述

我在第 12 行的扫描仪上收到了 NZEC,我在这里阅读了一些博客和几个问题,说问题正在关闭流,但我不明白发生在哪里。这个错误只发生在ideone上,它不会发生在netbeans上。

public static void main (String[] args) throws java.lang.Exception
{
    int t;
    List<Integer> k = new ArrayList();
    Scanner in = new Scanner(System.in);

    do {
        //Exception in thread "main" java.util.NoSuchElementException happens on this line
        t = Integer.parseInt(in.next());
    } while (t < 0 || t > 1000000);

    do {
        k.add(Integer.parseInt(in.next()) + 1);
        t--;
    } while (t > 0);

    for (int num : k) {
        while (!isPrime(num)) {
            num++;
        }
        System.out.println(num);
    }
}

标签: javapalindromenosuchelementexception

解决方案


推荐阅读