ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1007. Кодовые слова

how to determine the end of the console's input with Java
Послано robinpjl 15 сен 2009 23:41
THX
Re: how to determine the end of the console's input with Java
Послано Sergey Lazarev (MSU Tashkent) 16 сен 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
Послано robinpjl 16 сен 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
Послано Alex Tolstov (Vologda STU) 16 сен 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