When you apply an arithmetic operator to two different primitive types, the "narrower" one undergoes a "widening conversion." You can read all about the different types of conversion in the
Java Language Specification (look for §5.1.2, but it is by no means easy reading).
Another way to look at it is that when you try
double / int
the compiler alters it to
double / double
and double arithmetic permits division by zero.
Try it with k = 0.0 and see what happens