You have an infinite loop in your program:
for(inte.equals(1);inte.compareTo(BigInteger.ZERO)>=0;inte.add(BigInteger.ONE))
inte.equals(1)
always evaluates to true
and as a bonus does nothing.
inte.compareTo(BigInteger.ZERO) >= 0
is always true
(that's why the for
loop will never terminate) because inte
is always equal to 1
inte.add(BigInteger.ONE)
- returns a new BigInteger
and doesn't modify inte
(BigInteger
is an immutable class) - hence inte
will always be equal to 1.
What you want is probably (I assume what you want is: calculate a factorial of bv
):
while (inte.compareTo(bv) <= 0) {
fa = fa.multiply(inte);
inte = inte.add(BigInteger.ONE);
}
Correct handling of fact(0)
is left as an exercise for the reader.