File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

if statement

 
prerna boja
Ranch Hand
Posts: 67
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,


I have a question like :

Print Average if grade is less than 80 Sbut greater than 70.

For this question Should I use && (and) operator in the if block or the ||(or) operator. because it is given as but ,I am bit not sure. Please help me out.

Tell me which statement should I use:
1) if(number >70 && number<80)
2) if(number >70 || number<80).
 
David Harkness
Ranch Hand
Posts: 1646
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you understand which grades should be included in the statement "grade is less than 80 but greater than 70"? Is 90 included? How about 60?

If you're still confused by but, look at the two options you've posted. Do they both make sense? What range of grades would each allow to pass the if condition?
 
Rick Portugal
Ranch Hand
Posts: 243
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is #1.

"if(number >70 && number<80)" means "If the number is greater than 70 and the number is less than 80". That's what you want.

If you did "if(number >70 || number<80)" you would get all numbers because all numbers are greater than 70 OR less than 80.
 
Surasak Leenapongpanit
Ranch Hand
Posts: 341
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"if(number >70 && number<80)" is in range (70, 80) but
"if(number >70 || number<80)" in in range ANY NUMBERS
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic