Thread: Easy Question
View Single Post
Old 2009-10-01, 16:33   #5
Mini-Geek
Account Deleted
 
Mini-Geek's Avatar
 
"Tim Sorbera"
Aug 2006
San Antonio, TX USA

17×251 Posts
Default

Here's an example in Java that uses BigInteger, an arbitrary-precision integer, and prints every factorial up to the size you specify:
Code:
import java.math.BigInteger;
public class Main {
    public static void main(String[] args) {
        factorialWithBigIntNoDiv(100);
    }

    public static void factorialWithBigIntNoDiv(long n) {
        BigInteger fact = BigInteger.ONE;
        for (BigInteger i = fact; i.compareTo(BigInteger.valueOf(n)) <= 0; i = i.add(BigInteger.ONE)) {
            fact = fact.multiply(i);
            System.out.println(i + "! = " + fact);
        }
    }
}

Last fiddled with by Mini-Geek on 2009-10-01 at 16:34
Mini-Geek is offline   Reply With Quote