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

Problem in Java
Posted by Rizwan Ahmed 29 Jul 2008 01:38
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
Posted by Meni Packeou 14 Aug 2008 14:41
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
Posted by Meni Packeou 14 Aug 2008 14:50
If no decides write form



Edited by author 14.08.2008 21:52
Re: Problem in Java
Posted by Jack 26 Aug 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.(но когда я читаю из файла, программа работеат отлично)