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 1007. Code Words

how to determine the end of the console's input with Java
Posted by robinpjl 15 Sep 2009 23:41
THX
Re: how to determine the end of the console's input with Java
Posted by Sergey Lazarev (MSU Tashkent) 16 Sep 2009 00:15
Scanner in;
while (in.hasNext()){...} (for String)
or
while (in.hasNextType()){...} (for Type = Int, Double, Byte, ...)


BufferedReader in;
int c;
while ((c=in.read()) != -1) {...}


StreamTokenizer in;
in.nextToken();
while (in.ttype != StreamTokenizer.TT_EOF){
   ...
   in.nextToken();
}

Edited by author 16.09.2009 00:17
Re: how to determine the end of the console's input with Java
Posted by robinpjl 16 Sep 2009 15:18
i think ,second method(use -1 to end input) can't ac this problem with JAVA,
and i try to use first Scanner method to solve it,failed
,and TT_EOF is -1 in nature.
Re: how to determine the end of the console's input with Java
Posted by Alex Tolstov (Vologda STU) 16 Sep 2009 15:45
the second method is correct.

Quote from java.sun.com:
>>
read

public int read()
         throws IOException

    Read a single character.

    Returns:
        The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
    Throws:
        IOException - If an I/O error occurs

<<
http://java.sun.com/j2se/1.5.0/docs/api/java/io/BufferedReader.html#read%28%29