Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

if statements

 
Bob Holland
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if ( i >= 30 && i <= 40 ) { }
 
Junilu Lacar
Bartender
Pie
Posts: 7778
62
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"between 30 and 40"

can be restated as

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

or

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

the logical "and" operator normally used in Java is &&
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Bob Holland
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow, thanx a lot, i was stumped for ages, thanx again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic