This is oddly my first Java application, I was wanting to implement an arbitrary precision factorial function, I did the recursive one fine but my iterative one simply outputs "1" and nothing else.. It is so late for me I can not spot why, I am not sure where I went wrong, is there something obvious here?
public static BigInteger ifact(BigInteger n) {
BigInteger ret = new BigInteger("1");
BigInteger i = new BigInteger("1");
for(i = new BigInteger("0"); i.compareTo(n) == 0; i.add(new BigInteger("1"))){
ret.multiply(i);
}
return ret;
}
In case you did not notice it uses the BigInteger package, hense the odd writings..
Also, like C, can you do something similar to typedef so I don't need to type "BigInteger" each time?
EDIT: I think I meant to set ret
as n
, that may be it, or..maybe not.