Created
August 20, 2013 09:14
-
-
Save sshark/6279141 to your computer and use it in GitHub Desktop.
Factorial with BigInteger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hp.hpls.monsoon.servicecat.service.impl; | |
import java.math.BigInteger; | |
/** | |
* | |
* @author Lim, Teck Hooi | |
* | |
* | |
*/ | |
public class Factorial { | |
public static void main(String[] args) { | |
System.out.println(fac(BigInteger.valueOf(100000))); | |
} | |
public static BigInteger fac(BigInteger j) { | |
if (j.equals(BigInteger.valueOf(0))) { | |
return BigInteger.valueOf(1); | |
} | |
return fac((j.add(BigInteger.valueOf(-1)))).multiply(j); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment