aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Unable to understand result of this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Unable to understand result of this code" Watch "Unable to understand result of this code" New topic
Author

Unable to understand result of this code

gurneeraj singh
Ranch Hand

Joined: Mar 19, 2008
Posts: 80

How we solve equation in line 1.

[ March 22, 2008: Message edited by: gurneeraj singh ]

SCJP 5.0 93%<br /> <br />SCWCD 5.0 97 %
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1818
    
    7

The output will be "Mercury" and only the logic to the left of the || operator will ever be evaluated for the given boolean values.

You can read line 1 as:

if both b1 and b2 are true, execute the if-body immidiately.
OTHERWISE
if either b3 or b4 are true, or both are, execute the if-body.
OTHERWISE
execute the else body.

An equivalent if-else structure would be:


Remeber that in the abscence of parentheses the order of precendence for boolean operators is (highst priority first):
1. &
2. |
3. &&
4. ||
[ March 22, 2008: Message edited by: Jelle Klap ]

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to understand result of this code