0
Arithmetic operations
Why answer is 2? int x = 19; int y = 7; System.out.print(x/y%3)
2 Respuestas
+ 7
Let's break it into pieces:
/ and % have same precedence. So we start from left to right.
x/y == 19 / 7 == 2.71.....
But both x and y are integers.
Division (/) operator must return an int when both operands are ints. 2.71... is truncated to 2.
Now 2 % 3.
% is the remainder operator.
2/3 is 0 remainder 2.
Answer is 2
+ 1
thx