I want to run an if statement if an integer is between 2 values. I can do this by using two if statements, but can I avoid this repetition? I want something like this: if(x > 1 AND x < 7){ out.println("x is between 1 and 7"); } Clearly "and" isn't right, but what is? I note that you can seperate expressions in a "for" statement with ";", but this doesn't work in an if statement. Any ideas? Thanks, James
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
posted
0
You might want to get a book on Java. There are some free ones online. Here you go...
if( (x > 1) && (x < 7) ){ Do whatever
Bosun
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
James Hewitt
Greenhorn
Joined: Jul 09, 2001
Posts: 27
posted
0
Thanks for that. Got a java book. It really sucks. Thanks, James
Guy Reynolds
Ranch Hand
Joined: Oct 27, 2000
Posts: 61
posted
0
Hey James, when I first started posting here I made the grande faux pas of asking who Simon Roberts, Philip Heller and Michael Ernest were. I think I'm still receiving hate mail over that! Anyway, the point is, they wrote a really good book on Java. I'm not sure if I can post the title here, I have no idea what the "rules" on promoting products are, but you should be able to find it easily, it's a study guide. p.s. I also made the mistake of questioning whether the second edition is as good as the first. Apparently it is. I haven't compared the two, I just accepted everyone's opinion (including Mr. Roberts) and purchased it... and since reading it, I've recommended it to everyone that asks.
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
We talk about authors and their books ALOT here, seems techies just LIKE books . Anyway we have a whole section called the BunkHouse devoted to Book Reviews as well as a Book Review forum for conversations about books. The comment above should probably be added to the thread for the RHE book here: http://www.javaranch.com/ubb/Forum49/HTML/000081.html
"JavaRanch, where the deer and the Certified play" - David O'Meara
Roy Tock
Ranch Hand
Joined: Jul 16, 2001
Posts: 83
posted
0
James, there's no other way to do it. You've got to repeat x twice.