Mailing List ArchiveSupport open source code!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: java question
- To: tlug@example.com
- Subject: Re: java question
- From: "Thomas O'Dowd" <tom@example.com>
- Date: Thu, 14 Jun 2001 16:55:20 +0900
- Content-Disposition: inline
- Content-Type: text/plain; charset=us-ascii
- In-Reply-To: <3B286744.CC3849EA@example.com>; from 9915104t@example.com on Thu, Jun 14, 2001 at 04:27:00PM +0900
- References: <3B278493.388731B4@example.com> <20010614004711.B657@example.com> <3B286744.CC3849EA@example.com>
- Reply-To: tlug@example.com
- Resent-From: tlug@example.com
- Resent-Message-ID: <Slv5KD.A.PK.izGK7@example.com>
- Resent-Sender: tlug-request@example.com
- User-Agent: Mutt/1.2.5i
On Thu, Jun 14, 2001 at 04:27:00PM +0900, B0Ti wrote: > Thomas O'Dowd wrote: > > > use a loop with an exit condition, or an infinite loop with a break, or ... > > > > int someInt; > > while() > > { > > try > > { > > someInt = Integer.parseInt(readUserInput()); > > if(someInt >= 1 && someInt <= 10) > > break; > > } > > catch (NumberFormatException) > > { > > ; > > } > > } > > > > This is how I started doing it initially, but if I used somInt after the catch > statement javac said: cannot resolve symbol. The "finally" statement solved > it. If you declare someInt within the while block, its scope will be that block and you won't be able to use it outside the while loop. If you declare it outside as above, it should work, although java will probably complain that the variable someInt may not be initialised if you use it after the while loop (this is because javac just sees that an exception may be thrown during parseInt() and someInt may never be defined, although we are looping to prevent that anyway). You can solve this by initialising it to some default value (0) when you declare it although it should never be uninitialised in this case. There is no real need for a finally statement in this case that I can see. finally is just used to perform tidyup at the end of a try block no matter what path execution takes through the try. The while loop should read, "while(true)" and not "while()". I guess it was late when I wrote it :) Tom. -- Thomas O'Dowd. - Nooping - http://nooper.com tom@example.com - Testing - http://nooper.co.jp/labs
- Follow-Ups:
- Re: java question
- From: "Stephen J. Turnbull" <turnbull@example.com>
- References:
- java question
- From: B0Ti <9915104t@example.com>
- Re: java question
- From: "Thomas O'Dowd" <tom@example.com>
- Re: java question
- From: B0Ti <9915104t@example.com>
Home | Main Index | Thread Index
- Prev by Date: Re: java question
- Next by Date: Stallman (Was: Unicode TTF containing CJK?)
- Prev by thread: Re: java question
- Next by thread: Re: java question
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links