Versions Compared

Key

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

...

Code Block
bgColor#ccccff
public int do_operation(int a, int b) throws ArithmeticException {
  if( (b>0 &&? (a > Integer.MAX_VALUE - b)) || (b<0 && (: a < Integer.MIN_VALUE - b)) ) {
    throw new ArithmeticException();
  }
  return a + b;  //Value within range can perform the addition
}

...

Code Block
bgColor#ccccff
public int do_operation(int a, int b) throws ArithmeticException {
  if( (b>0 &&? (a < Integer.MIN_VALUE + b)) || (b<0 && (: a > Integer.MAX_VALUE + b)) ) {
    throw new ArithmeticException();
  }
  return a - b;  //Value within range can perform the addition
}

...