$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #236

Which fix removes the bug?

int days = 30;
long ms = days * 24 * 60 * 60 * 1000;
System.out.println(ms); // -1702967296
  1. Cast the result: (long) (...)
  2. Declare ms as a double instead
  3. Wrap the result in Math.abs
  4. 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 ▸