I have this weird kind of error.
I am trying implement basic Euclidean algorithm using the BigInteger class as shown. When i run it, it throws StackoverFlowError, while if i debug it, it runs through correctly and gives me the correct answer.
I seriously dont understand the difference during debug and normal run.
static BigInteger gcd(BigInteger a, BigInteger b) {
if (a.equals(BigInteger.ZERO)) {
return b;
} else if (b.equals(BigInteger.ZERO)) {
return a;
}
BigInteger max = a.max(b);
BigInteger min = a.min(b);
return gcd(max.subtract(min), min);
}