hi,
the operator precedence for the operators available in
java can be found at the following link:
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html From the table shown in the above link,
we can classify the precedences of the operators specific to the given expression "i = 4*6-3/2<<2*5>>>1%2-4^3" as follows:-
Note:- For simplicity, we assign numbers to the set of operators
Precedence Operator
---------- --------
1 * / %
2 -
3 << >>>
4 ^
5 =
Thus,
The given expression gets executed as:
Step1: * / % are executed
i = 24 - 1.5 << 10 >>> 1 - 4 ^ 3
Step2: - is executed
i = 22 << 10 >>> -3 ^ 3 // notice here that 22.5(24 - 1.5) becomes 22
Step3: << >>> are executed
i = 22528 >>> -3 ^ 3
i = 0 ^ 3 // when operators of equal precedence occur,left to right
// execution occurs. this idea can also be understood from
// the associativity property of each operator used in java
Step4:
i = 3