Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1010

Re: Newbie seeking comments on StdinReader class

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From markspace <-@.>
Newsgroups alt.comp.lang.java, comp.lang.java.help, comp.sources.d
Subject Re: Newbie seeking comments on StdinReader class
Date Mon, 05 Sep 2011 08:42:22 -0700
Organization A noiseless patient Spider
Lines 34
Message-ID <j42qld$79v$1@dont-email.me> (permalink)
References <d7333ac9-4b0e-41b3-854d-7c2486e3fd5b@33g2000yqu.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 5 Sep 2011 15:42:38 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="7487"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XP+GiS5HAbO4g7jFX5bJwdsAxdKFtRP0="
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1
In-Reply-To <d7333ac9-4b0e-41b3-854d-7c2486e3fd5b@33g2000yqu.googlegroups.com>
Cancel-Lock sha1:FvpjENdurNRqJeNqV7xdNvkkpCk=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.help:1010 comp.sources.d:39

Cross-posted to 3 groups.

Show key headers only | View raw


On 9/5/2011 7:00 AM, anirudhbhat9@yahoo.com wrote:
> Greetings,
>
> I am a Java newbie and I have created a class which reads input from
> Stdin.  I want the class to silently block until the user enters the
> correct input.


This is what I came up with.  Whether it's really better or not I think 
depends on your requirements.  Lightly tested.


    public static int test3( InputStream ins )
            throws MyEndOfInputException
    {
       Scanner scanner = new Scanner( ins );
       while( scanner.hasNext() ) {
          if( scanner.hasNextInt() )
             return scanner.nextInt();
           else
             scanner.next();
       }
       throw new MyEndOfInputException();
    }
}

class MyUtilsException extends Exception
{
}

class MyEndOfInputException extends MyUtilsException
{
}

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Newbie seeking comments on StdinReader class anirudhbhat9@yahoo.com - 2011-09-05 07:00 -0700
  Re: Newbie seeking comments on StdinReader class markspace <-@.> - 2011-09-05 08:42 -0700
  Re: Newbie seeking comments on StdinReader class langrenfengzi <langrenfengzi@myopera.com> - 2011-09-10 21:22 +0800
  Re: Newbie seeking comments on StdinReader class Roedy Green <see_website@mindprod.com.invalid> - 2011-09-10 20:12 -0700

csiph-web