Q:

Division returns unexpected 0 if result is declared as double

From the following code
x = 2 / 5
double y = 2 / 5
double z = 2.0 / 5
println(String.format("%f %f %f", x, y, z))

we get the output
0.4 0.0 0.4

Why is the value of y 0.0?  What is the reason for this unintuitive behaviour?

A:

Because dividing two integers (2 and 5) gives that result 0, which is then converted to double.

