aspose file tools*
The moose likes Beginning Java and the fly likes if statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "if statement" Watch "if statement" New topic
Author

if statement

prerna boja
Ranch Hand

Joined: Aug 19, 2004
Posts: 67
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

Joined: Aug 07, 2003
Posts: 1646
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

Joined: Dec 17, 2002
Posts: 243
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.


IBM 286, SCJP, SCWCD, EIEIO
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
"if(number >70 && number<80)" is in range (70, 80) but
"if(number >70 || number<80)" in in range ANY NUMBERS
 
 
subject: if statement