ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

Java Runtime error
Posted by Roma 2 Aug 2016 12:22
Can you please explain - why the code below generates Runtime error during checking ? Thanks,

import java.util.*;

public class Task0002 {

    public static void main(String[] args) {
        Scanner scin = new Scanner(System.in);
        ArrayList<Double> values = new ArrayList<Double>();
        String strIn;
        int lenScin = 0;
            do {
                strIn = scin.nextLine();
                lenScin += strIn.length();
                strIn = strIn.trim();
                strIn = strIn.replaceAll("  ", " ");

                // Process the line
                    if(strIn.length()>0) {
                        for(String s: strIn.split(" ")) {
                        values.add(Double.parseDouble(s));
                        };
                    };

            } while(scin.hasNextLine() && lenScin <= 262144);
        scin.close();

        for(int i = values.size()-1; i>=0; i--) {
        double val = (double)values.get(i);
        System.out.println(Math.sqrt(val) + " ");
        };

    }

}

Edited by author 02.08.2016 12:29
Re: Java Runtime error
Posted by Alexander_Fedotov_TverSU 2 Aug 2016 22:01
May be you also need to replace '\n' ?