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

If condition

asha ganapathy
Ranch Hand

Joined: Nov 03, 2006
Posts: 54
please let me know where i am going wrong
In my opinion the x value should be 2, but the answer is 4.
aslika bahini
Ranch Hand

Joined: Mar 03, 2007
Posts: 111
Hi asha,

else if(b=false){ // yes b is false here

orginally posted by asha

here.. you are assigning b=false.

if, b == false then, it prints x = 2


Praveen Seluka
Ranch Hand

Joined: Jul 17, 2007
Posts: 95

The second condition
else if (b=false) is an assignment operation.It assigns b to false and then the if loop becomes false so it wont be x=2.

Praveen SP
asha ganapathy
Ranch Hand

Joined: Nov 03, 2006
Posts: 54
ok i got it thanks a lot
I agree. Here's the link:
subject: If condition
It's not a secret anymore!