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

From markspace <-@.>
Newsgroups alt.comp.lang.java, comp.lang.java.help, comp.sources.d
Subject Re: Newbie seeking comments on StdinReader class
Date 2011-09-05 08:42 -0700
Organization A noiseless patient Spider
Message-ID <j42qld$79v$1@dont-email.me> (permalink)
References <d7333ac9-4b0e-41b3-854d-7c2486e3fd5b@33g2000yqu.googlegroups.com>

Cross-posted to 3 groups.

Show all headers | 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