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

Operator: & ^ |

 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused!!! I have compiled this code and I don't get the same results manually. Can someone please explain the following:
n = 7;
n = n & n + 1 | n + 2 ^ n + 3;
n = 57;
Here's how I'm figuring this out:
n = 7;
n = ( n & n ) + ( 1 | n ) + ( 2 ^ n ) + 3;
n = 56 + 57 + 58 + 3;
n = 174;
So, why isn't this right?
Thanks for the help!
 
Maverick Lasa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shannon Sims:

n = 7;
n = n & n + 1 | n + 2 ^ n + 3;

this will be executed as:

refer to Java Expressions
mavedrive;
 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh...the order of precendence. Got it. Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic