Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
operators question
david lightman
Ranch Hand
Posts: 82
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
this one is confusing me a little to follow.
classSSBool{ public static void main (String[] args){ boolean b1 = true; boolean b2 = false; boolean b3 = true; if( b1 & b2 | b2 & b3 | b2) System.out.println("ok "); if( b1 & b2 | b2 & b3 | b2 | b1) System.out.println("dokey"); } }
a-ok
b-dokey
c-ok dokey
d-no output
e-compile err
f-exception at runtime
all the &' are evaluated before |'s right, then just go left to right
if( b1 & b2 | b2 & b3 | b2) goes: true & false is false and false and true are false so im left with F | F | T the it goes: F | F is false and finally F | T = true
so answere is b, dokey
is this the simple way you guys work them out?
thank you
James Chegwidden
Author
Posts: 201
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Well the problem is using & and | the unconditional operators- where the right side is always evaluated. short circuit evaluation is not used.
Looks OK.
JC
Author and Instructor,
my book
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Explanation of Program
clarification if condition
K & B boolean Question
Have a question about operators
Doubt on Self Test Question
More...