How can I get a double result from dividing two ints?
In Java, the division of two numbers of which at least one is a double always yields a double result. However, dividing two ints always yields an int — this is the result of so-called “integer division”, in which any fractional portion of the result is truncated. How can we get a double result from dividing two ints? By first casting one or both of the integer arguments to a double. Here are some examples: Java Expression Value 7 / 2 3 7.0 / 2 3.5 7 / 2.0 3.5 7.0 / 2.0 3.5 ((double) 7) / 2 3.5 7 / ((double) 2) 3.5 (double) (7 / 2) 3 (double) 7 / 2 3.5 ((int) 7.