JAVA 格式化输入后uva在线判断运行时错误

JAVA Runtime error in uva online judge even after formatting input

我正在解决关于 UVA 的问题。它不断给出运行时错误。在阅读了 Whosebug 上类似问题的答案后,我修改了我的代码以以正确的格式输入,但仍然存在运行时错误。

请指出我的代码有什么问题? 这是问题link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=36

Java中的代码:

class P100 {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        long a[] = new long[1000000];
        Scanner sc ;

        String line = "  ";
        while ((line = br.readLine()) != null) {
            sc=new Scanner(line);
            long l,r;
            if(sc.hasNextLong())
             l = sc.nextLong();
            else
                break;
            if(sc.hasNextLong())
            r = sc.nextLong();
            else
                break;
            long i = l, j = r;
            if (l > r) {
                i = r;
                j=l;
            }
            long max = Long.MIN_VALUE;
            for (long k = i; k < r + 1; k++) {
                if (a[(int)k] == 0) {
                    a[(int)k] = countCycleLength(k);
                }
                if (max < a[(int)k]) {
                    max = a[(int)k];
                }
            }
            System.out.println(l + " " + r + " " + max);

        }

    }

    static long countCycleLength(long j) {
        long count = 1;
        while (j != 1) {
            if (j % 2 != 0) {
                j = j * 3 + 1;
                j = j / 2;
                count += 2;
            } else {
                j = j / 2;
                count++;
            }

        }

        return count;
    }

    static long ip(String s) {
        return Long.parseLong(s);
    }

}

最后,我通过将 class 的名称从 P100 更改为 Main 并将 for 循环的条件更改为 k < j+1 来接受此代码。