I know that the array operator is the priority then the binary arithmetic operators *, /, then + and - which have less priority .
But I am confused that in this example, Java will be solved first. And if we have 2 operators of the same priority, then what operator will be used first in Java
Thank you.
int x = y = -2 + 5 * 7 - 7/2% 5; If someone can solve it for me and explain to me the part from the part. Because it always confuses me in the examinations.
If operators have the same priority then they are right from left. From
to:
When operators are shown the same priority in the same expression, then rule should rule which is evaluated for the first time. Except the assignment operator, all binary operators are evaluated from left to right; Assignment operators have been properly evaluated.
In expression, 7/2% 5 , / and % are the same priority, therefore Going 7/2 = 3 and 3% 5 = 3 above the right. The top priority is given * /% breakdown of your example is here:
-2 + 5 * 7 - 7/2% 5 = -2 + ( 5 * 7) - (7/2% 5) = -2 + 35 - (3% 5) = -2 + 35 - 3 = 30
Comments
Post a Comment