|
|
вернуться в форумI really don't know why it is wrong(Java Scrip) Hi, I tried to use java to solve this problem but failed, yet do not know where is the bug, I have pasted the source code here, wish someone can help me out. I am very very grateful. public class ReversRoot1001 { public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new FileReader("ReversRoot1001.txt")); Vector<Integer> record = new Vector<Integer>(); String line; while((line = br.readLine())!=null){ Scanner sc = new Scanner(line); int a = sc.nextInt(); record.add(a); // if(sc.hasNext()){ // int b = sc.nextInt(); // //int c = sc.nextInt(); // record.add(b); // } while(sc.hasNext()){ int b = sc.nextInt(); record.add(b); } } for(int i = record.size();i<record.size();i--){ System.out.println(record.get(i)); } br.close(); } } Re: I really don't know why it is wrong(Java Scrip) Use standart input/output. And don't use Scanner - it's very slow. Look: BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); StringTokenizer tok = null; String readToken() throws IOException { // reads the token; to read a full line use in.readLine() while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); // sometimes it's better to use nextToken(String) method here } int readInt() throws IOException { // write readDouble(), readLong(), readBigInteger() methods if necessary return Integer.parseInt(readToken()); } And, finally, don't forget to write out.flush() at the end of your program! Edited by author 17.08.2010 21:26 Re: I really don't know why it is wrong(Java Scrip) Moonstone Thank you so much for your help. I am very grateful! Edited by author 18.08.2010 06:21 |
|
|