Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1028
| From | langrenfengzi <langrenfengzi@myopera.com> |
|---|---|
| Newsgroups | alt.comp.lang.java, comp.lang.java.help, comp.sources.d |
| Subject | Re: Newbie seeking comments on StdinReader class |
| Date | 2011-09-10 21:22 +0800 |
| Organization | Netfront http://www.netfront.net/ |
| Message-ID | <op.v1lgsbku1djqkw@langrenfengzi> (permalink) |
| References | <d7333ac9-4b0e-41b3-854d-7c2486e3fd5b@33g2000yqu.googlegroups.com> |
Cross-posted to 3 groups.
在 Mon, 05 Sep 2011 22:00:39 +0800,<anirudhbhat9@yahoo.com> 写道:
The key sentence:
> I want the class to silently block until the user enters the
> correct input.
Here is my solution.It's a method named readInt, other methods are similar.
import java.util.Scanner;
public class StdinReader{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println(readInt(scanner));
}
public static int readInt(Scanner scanner){
int digit = 0;
while(true){
try{
digit = Integer.parseInt(scanner.next());
break;
}catch(Exception e){
}
}
return digit;
}
}
--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar
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