Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Since the long type is guaranteed to hold the result of an int addition, we can assign the result can be assigned to a long, and if the result is in the integer range, we can simply downcast to an int.

...

The remainder operation is safer in Java than the corresponding modulo operator in C/C++.

  • If we take the modulo of Integer.MIN_VALUE with -1 is taken the result is always 0 in Java.

...