int base, power, result = 1;
for (int i = 1; i <= power; i++) {
result *= base;
}
System.out.println(base + " to the power of " + power + " result: " + result);
10 to the power of 9 result: 1000000000
but;
10 to the power of 10 result: 1410065408
In my application this is logically an error but how can I detect this error before the println? for instance, when this error occurs, I want to print "result data type is int 32bit, it must not exceed 2,147,483,647"
How can I catch these kinds of errors?