Skip to content

Instantly share code, notes, and snippets.

@sshark
Created August 20, 2013 09:14
Show Gist options
  • Save sshark/6279141 to your computer and use it in GitHub Desktop.
Save sshark/6279141 to your computer and use it in GitHub Desktop.
Factorial with BigInteger
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