This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Campbell Ritchie wrote:You have four operators in that expression. They have different precedences
= Lowest Precedence
+ Higher than = and lower than %
% Higher than + and lower than -
- This is here a unary operator, and unary prefix operators have higher precedence than the others in that statement.
See whether that helps.
Yeah,thanks for the reply.I don't know what happens to my maths
But please tell me how 2%-8=2 ?
I know that in C , the sign of result by modulus operator is the sign of numerator.
So that 4+2=6.
Joined: Oct 13, 2005
Sorry for the delay in replying.
You have answered your own question. The sign of the result of the remainder operator is the same as the left-hand operand, so 2 % 8 and 2 % (-8) both return 2. I wrote (-8) instead of -8 to remind you of the relative precedences of the operators.