![]() |
|
|
|
#1 |
|
I have this code:
int i = -5; while ((i<0) & (i>=100)) i = Integer.parseInt(stdin.readLine()); // stdin is a BufferedReader It's supposed to repeatedly read the users input until the user types a number between 0 and 100. However, whenever I start the program it accepts that i=-5 and an error occurs because of this. Why? Gajo gajo |
|
|
|
|
#2 |
|
Posts: n/a
|
"gajo" wrote... > int i = -5; > while ((i<0) & (i>=100)) > i = Integer.parseInt(stdin.readLine()); > // stdin is a BufferedReader > > It's supposed to repeatedly read the users input until > the user types a number between 0 and 100. The condition you have written can *never* evaluate to true. (i can never be *both* less than zero *and* greater or equal to 100). I guess you're looking for: while ((i < 0) || (i >= 100)) Bjorn A Bjorn Abelli |
|
|
|
#3 |
|
Posts: n/a
|
I should probably say something like "arrrrgh!" now, right?
gajo |
|
|
|
#4 |
|
Posts: n/a
|
sok, many of us have been in your shoes before
"gajo" <> wrote in message news:boou74$i4$... > I should probably say something like "arrrrgh!" now, right? > > nos |
|
|
|
#5 |
|
Posts: n/a
|
gajo wrote:
> I have this code: > > int i = -5; > while ((i<0) & (i>=100)) > i = Integer.parseInt(stdin.readLine()); > // stdin is a BufferedReader > > It's supposed to repeatedly read the users input until the user types a > number between 0 and 100. However, whenever I start the program it accepts > that i=-5 and an error occurs because of this. > Why? I don't know what you mean by "an error occurs", but it's clearly not possible to satisfy the condition "((i < 0) & (i >= 100))", so the input will never actually happen. Perhaps you meant "|" (and it's better to use the short-cutting operators unless you have a specific reason not to, so I'd use "||" instead.) -- www.designacourse.com The Easiest Way to Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation Chris Smith |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| please help: simple java coding error 'cannot be referenced from a static context' | clm90 | General Help Related Topics | 0 | 10-17-2009 06:49 AM |
| Stupid Runner Error | GMB | General Help Related Topics | 3 | 01-23-2008 09:51 PM |
| Need help on Modelsim VHDL syntax? ASAP:) | kaji | General Help Related Topics | 0 | 03-14-2007 10:43 PM |
| Need help on a Modelsim VHDL Syntax? ASAP:) | kaji | Software | 0 | 03-14-2007 10:43 PM |
| Need Help on a Modelsim VHDL Syntax....ASAP:) | kaji | Hardware | 0 | 03-14-2007 10:41 PM |