Skip to content

Instantly share code, notes, and snippets.

@M-ZubairAhmed
Created February 13, 2017 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save M-ZubairAhmed/cdd87cd0c20ec6ce137a029f801d6b43 to your computer and use it in GitHub Desktop.
Save M-ZubairAhmed/cdd87cd0c20ec6ce137a029f801d6b43 to your computer and use it in GitHub Desktop.
Calculating factorial of huge numbers using BigInteger Java class.
//bNum = Initializing big interger to value.
BigInteger bNum = BigInteger.ONE;
// n = The input number whose factorial is to be calculated.
for (long i = 1; i <= n; i++) {
bNum = bNum.multiply(bNum.valueOf(i));
}
//Storing the value of factorial in a string.
String factorialValue = String.valueOf(bNum);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment