|
|
back to boardJava 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 May be you also need to replace '\n' ? |
|
|