aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K & B  boolean Question 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 "K & B  boolean Question" Watch "K & B  boolean Question" New topic
Author

K & B boolean Question

RAGU KANNAN
Ranch Hand

Joined: Dec 16, 2005
Posts: 103
Hello Folks,

somebody Can explaint how the line1 become false and line2 become true.

Thanks, Raghu.K


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18843
    
  40

This question has appeared on this forum before -- just use the search link above to look for either "SSBool" or "dokey".

Basically... the key to getting the answer is an understanding that the bitwise AND operator has a higher precedence than the bitwise OR operator.

Henry
[ September 20, 2006: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Alangudi Balaji Navaneethan
Ranch Hand

Joined: Apr 28, 2004
Posts: 42
hi,

Its simple you evaluate from left to right and replace every expression with its value you'll get the answer.

line 1:

if (b1 & b2 | b2 & b3 | b2)

if( true & false | false & true | false) became
if(false | false & true | false) after evaluating true & flase to false. Then that became
if(false & true | false) after evaluating false | false to false. After that false & true gave false then false | false gave false as a result.

For Line 2:
Its just performing line 1 result | b1. b1 is true. hence false (result of line 1) | true yields true.


I think you are clear now.


if you think you can you r right<br />if you think you can not you r double right
kwan Jang
Greenhorn

Joined: Sep 24, 2006
Posts: 16
"|" means or,and "&" means and!
Fred Chopin
Greenhorn

Joined: Sep 25, 2006
Posts: 2
Originally posted by Henry Wong:
This question has appeared on this forum before -- just use the search link above to look for either "SSBool" or "dokey".

Basically... the key to getting the answer is an understanding that the bitwise AND operator has a higher precedence than the bitwise OR operator.

Henry

[ September 20, 2006: Message edited by: Henry Wong ]


Simplest answer is it is all in operator precedence!


-- <br /> <br />Perhaps you are the best relief worker out there that could really help the children in distress. Work with UNICEF through the web at <a href="http://www.unicef.org" target="_blank" rel="nofollow">http://www.unicef.org</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K & B boolean Question