Sometimes a value of one type has to be used as another, like turning an average into a whole number or a char into its code. Java widens automatically when nothing is lost, but narrowing from double to int needs an explicit cast and drops the fraction. Cast before dividing when you need a decimal result, as in (double) sum / n. Do not cast to hide an overflow; use a bigger type like long from the start.