|
|
back to boardWhat is wrrong here?(in Java Compiler i get correct answer..) Posted by ABO 1 Nov 2008 00:42 import java.io.FileReader; import java.util.LinkedList; import java.util.Scanner; public class Pr1002 { public static void main(String[] args) { LinkedList<Long> listOfNum = new LinkedList<Long>(); try { Scanner sc = new Scanner(new FileReader(args[0])); while (sc.hasNext()) { listOfNum.addFirst(sc.nextLong()); } while (!listOfNum.isEmpty()) { System.out.printf("%.4f", Math.sqrt(listOfNum.removeFirst())); System.out.println(); } } catch (Exception e) { System.out.println(e.getMessage()); } } } Re: What is wrrong here?(in Java Compiler i get correct answer..) >> Scanner sc = new Scanner(new FileReader(args[0])); I think you're to assume all input comes from 'System.in' and not be specify as a program argument, so 'java myprogram inputfile.txt shouldn't work'. |
|
|