首页 > 解决方案 > 以下代码在 ideone 中出现运行时错误,但在 eclipse 和 bash 终端中运行良好

问题描述

我正在运行代码来计算BigIntegerString 中的一些值ArrayList。计算在外部完成ArrayList,然后作为字符串添加回列表。

该代码在 Ubuntu 终端和 Eclipse IDE 中运行良好,但在Ideone和其他在线 IDE 中出现运行时错误。

public static void main (String[] args) throws IOException
    {
        BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(kb.readLine());
        for(int i = 0; i<T; i++){
            int N = Integer.parseInt(kb.readLine());
            ArrayList<String> L = new ArrayList();
            //int[] L = new int[N];
            for(int j = 0; j<N; j++){
                L.add(Integer.toString(j+1));
            }
            while(L.size()>1){
                BigInteger x = new BigInteger(L.get(0).substring(0));
                BigInteger y = new BigInteger(L.get(L.size()-1).substring(0));
                L.remove(0);
                L.remove(L.size()-1);
                BigInteger fin = new BigInteger("0");
                fin = fin.add(x);
                fin = fin.add(y);
                fin = fin.add(x.multiply(y));
                String finstring = fin.toString();
                L.add(finstring);
            }
            int r = 0;
            for(int j = 0; j<L.get(0).length(); j++) {
                r = (r * 10 + (int)L.get(0).charAt(j) - '0') % 100000007; 
            }
            System.out.println(r);
        }
    }

标签: java

解决方案


您需要将输入分成两行,以便将它们作为单独的值。

从此更改输入值:

1 4

1
4

看到它在这里工作:https ://www.ideone.com/CkMCAn


推荐阅读