File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes if statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "if statements" Watch "if statements" New topic

if statements

Bob Holland

Joined: Dec 15, 2004
Posts: 7
hi there all, im trying to write a program something like this

if "percentage"(this is a variable) is between 30 and 40 then print .............

but i dont know the syntax for the between bit, i can do greater than, less than, and equal, but not between, please help me!!!
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
if ( i >= 30 && i <= 40 ) { }

Mike Gershman
SCJP 1.4, SCWCD in process
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

"between 30 and 40"

can be restated as

"greater than 30 and less than 40" (excluding 30 & 40)


"greater or equal to 30 and less than or equal to 40" (inclusive)

the logical "and" operator normally used in Java is &&

Junilu - [How to Ask Questions] [How to Answer Questions]
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Bob Holland

Joined: Dec 15, 2004
Posts: 7
wow, thanx a lot, i was stumped for ages, thanx again
I agree. Here's the link:
subject: if statements
It's not a secret anymore!