public class OverflowCheck {
static boolean multiplyWillOverflow(int x, int y) {
return Integer.MAX_VALUE / x < y;
}
public static void main(String[] args) {
int x = 3, y = 13727832;
System.out.println(multiplyWillOverflow(x, y) ? "true" : "false");
x = 1438839299; y = 3;
System.out.println(multiplyWillOverflow(x, y) ? "true" : "false");
}
}
/*
run:
false
true
*/