• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

if statement, 2 conditions

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
James Hewitt
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that. Got a java book. It really sucks.
Thanks,
James
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James, there's no other way to do it. You've got to repeat x twice.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic