Which fix removes the bug?
int days = 30; long ms = days * 24 * 60 * 60 * 1000; System.out.println(ms); // -1702967296
- Cast the result:
(long) (...) - Declare ms as a
doubleinstead - Wrap the result in
Math.abs - Make one factor long:
24L
The product is computed in int and overflows before it is widened; a long operand makes it long arithmetic.
Play Problem Solving ▸