This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Have a question about operators

 
chang nanny
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
class SSBool{

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");
}
}
}
output is kdokey
Could someone tell why the reason is "okdokey"?
Thank you.
 
C. Magmanum
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the output is
dokey
compare the values from left to right and evaluate with each step, u might get a better grasp.
 
Lionel Orellana
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by chang nanny:




& has higher precedence than |. So this is like saying

cheers
 
chang nanny
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic