Big Factorial!!! Have a fun..........
import java.math.BigInteger;
public class Factorial {
public static void main(String[] shan) {
BigInteger bigInteger = BigInteger.valueOf(1);
for (int i = 2; i <= 100; i++) // calculate 100!
bigInteger = bigInteger.multiply(BigInteger.valueOf(i));
System.out.println(bigInteger);
System.out.println("Length is: "+bigInteger.toString().length());
}
}
The output :::
933262154439441526816992388562667004907159682643816214
685929638952175999932299156089414639761565182862536979
20827223758251185210916864000000000000000000000000
Length is: 158
No comments:
Post a Comment