Files
java-tutorials/libraries/src/main/java/com/baeldung/junitparams/SafeAdditionUtil.java
T
2019-11-01 09:24:05 +01:00

16 lines
346 B
Java

package com.baeldung.junitparams;
class SafeAdditionUtil {
int safeAdd(int a, int b) {
long result = ((long) a) + b;
if (result > Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
} else if (result < Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
}
return (int) result;
}
}