0

Why we use in java / as modulo

System.out.println (8/3*2); output 4 Why?

9th Nov 2019, 8:28 PM
Walid Kamoun
Walid Kamoun - avatar
1 Answer
+ 8
% is used as modulo operator to return remainder, not /(it is for division) 8/3*2 is equivalent to ((8/3)*2) as precedence of / and * operator is same, and associativity is from Left to Right (8/3) is 2, as int/int returns an int in java with decimal part truncated, so 2*2 returns 4.
9th Nov 2019, 8:33 PM
Gaurav Agrawal
Gaurav Agrawal - avatar