Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #1028
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.lightlink.com!news.ripco.com!news.glorb.com!news.netfront.net!not-for-mail |
|---|---|
| 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 | Sat, 10 Sep 2011 21:22:49 +0800 |
| Organization | Netfront http://www.netfront.net/ |
| Lines | 37 |
| Message-ID | <op.v1lgsbku1djqkw@langrenfengzi> (permalink) |
| References | <d7333ac9-4b0e-41b3-854d-7c2486e3fd5b@33g2000yqu.googlegroups.com> |
| NNTP-Posting-Host | 119.80.125.81 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=gbk; format=flowed; delsp=yes |
| Content-Transfer-Encoding | Quoted-Printable |
| X-Trace | adenine.netfront.net 1315660973 84290 119.80.125.81 (10 Sep 2011 13:22:53 GMT) |
| X-Complaints-To | news@netfront.net |
| NNTP-Posting-Date | Sat, 10 Sep 2011 13:22:53 +0000 (UTC) |
| User-Agent | Opera Mail/11.51 (Win32) |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.help:1028 comp.sources.d:40 |
Cross-posted to 3 groups.
Show key headers only | View raw
在 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