Division and casting
Dividing two int values gives an int: the part after the decimal point is simply dropped, not rounded.
System.out.println(7 / 2);
System.out.println(9 / 10);
System.out.println(7.0 / 2);
3
0
3.5As soon as one of the two numbers is a double, like 7.0, the division gives a double. With variables, turn an int into a double with a cast: (double) in front of it.
int sum = 7;
int count = 2;
double average = (double) sum / count;
System.out.println(average);
3.5Where the cast goes matters. (double) sum / count turns sum into 7.0 first and then divides, giving 3.5. (double) (sum / count) divides the two int values first, giving 3, and then turns that into 3.0.