Java is a strongly typed language so you should be aware of the types of the values in expressions. If not…
1
is an int
(as 2
), so 1/2
is the integer division of 1 and 2, so the result is 0
as an int
. Then the result is converted to a corresponding double value, so 0.0
.
Integer division is different than float division, as in math (natural numbers division is different than real numbers division).