Module
I recently checked into a Java class and I have a question regarding module splitting.
I'll give an example in my tutorial:
( 100 - 25 * 3 % 4 ) = 97
How does it equal 97? I've tried all sorts of possibilities and I just can't figure it out.
Can anyone be so kind as to break it for me.
Thanks in advance.
+3
source to share
2 answers
The operators *, / and% are called multiplicative operators. They have the same precedence and are syntactically left-associative (they are grouped from left to right).
So whenever there is A op1 B op2 C and both op1 and op2 are *, / or%, which is equivalent
(A op1 B) op2 C
25 * 3 % 4 -> a * b % c
(25*3)%4->(a*b)%c
Operator (-) is right to the left. operator - Performs evaluation after the expression on the right hand side completes. so the answer is 100- (25 * 3)% 4 = 100-3 = 97
+1
source to share