wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes If----else Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "If----else" Watch "If----else" New topic
Author

If----else

Ash sav
Ranch Hand

Joined: Apr 14, 2001
Posts: 55
4) For what value of i, the following program will output "Not Greater than 10"
public class Base{
private void test() {
int i ;
if(i > 10)
System.out.println("Greater than 10");
else
if ( i < 10) <br /> System.out.println("Less than 10");<br /> else<br /> if ( i > 20)
System.out.println("Greater than 20");
else
System.out.println("Not Greater than 10");
}
static public void main(String[] a) {
new Base().test();
}
}
Select most appropriate answer.
a) 0
b) 10
c) 11
d) 100
e) None

I compiled this prog and I know the answer is 10 but I'm still confused how? The way i'm thinking is that 10>10 so it should print greate that 10 . Can somebody tell me?
Thanks in advance,
Ash
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4447
    
    5


Why would you think 10 > 10? (unless, of course, you are a troll)

Originally posted by Ash sav:
The way i'm thinking is that 10>10 so it should print greate that 10 . Can somebody tell me?


Junilu - [How to Ask Questions] [How to Answer Questions]
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
it prints "Not greater than 10" because 10 is equal to 10:
( 10 == 10 )
( 10 >= 10 )
( 10 <= 10 )
none of these options were in the code, so the "else" statement is executed. it is a trick question, so if you look at it wrong the first time, you will not get it.


what?
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
it prints "Not Greater than 10"
beacuse the conditions
10>10
10<10<br /> 10>20
all retun false. Hence it goes to the else clause.


Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: If----else
 
Similar Threads
Keyword this
oo concepts
Question
confusion in the output
Queries Again...