|
|
вернуться в форумProblem in Java I don't know that where to end Input Stream? My source code is below. import java.util.Scanner; import java.io.PrintWriter; public class Program { public static void main(String args[]) throws Exception { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter (System.out); double numbers[] = new double[100000]; int i =0; double result = 0.0; while(in.hasNext()) { numbers[i++] = in.nextDouble(); } i = i -1; while(i >= 0) { result = Math.sqrt(numbers[i]); out.println(result); i = i-1; } out.flush(); } } The first while loop is executing infinite time. Re: Problem in Java Problem no in Java.you write code correct but.Java have Thread class and it's to crawl all over code.
Edited by author 14.08.2008 14:42 Edited by author 14.08.2008 14:46 Re: Problem in Java If no decides write form Edited by author 14.08.2008 21:52 Re: Problem in Java Послано Jack 26 авг 2008 21:37 Thread? This is no working: (Потоки? Это всеравно не работает) import java.util.*; import java.io.*; public class BaseClass extends Thread{ public static Scanner in; private static void next() throws IOException{ if(in.hasNext()){ double t=in.nextDouble(); next(); double n=(double) Math.sqrt(t); System.out.printf("%.4f\n", new Float(n)); } } public void run(){ in=new Scanner(System.in); try { next(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) throws Exception{ BaseClass t=new BaseClass(); t.start(); } } But, if i reading data from file (in=new Scanner(new FileInputStream("in.txt"));) - this working.(но когда я читаю из файла, программа работеат отлично) |
|
|