Java's BigInteger class
// Java program to find large factorials using BigInteger
import java.math.BigInteger;
import java.util.Scanner;
public class Example
{
// Returns Factorial of N
static BigInteger factorial(int N)
{
// Initialize result
BigInteger f = new BigInteger("1"); // Or BigInteger.ONE
// Multiply f with 2, 3, ...N
for (int i = 2; i <= N; i++)
f = f.multiply(BigInteger.valueOf(i));
return f;
}
// Driver method
public static void main(String args[]) throws Exception
{
int N = 20;
System.out.println(factorial(N));
}
}
Also in Java:
- java program to display characters from a to z using loop
- java string reverse
- count the number of words in a string java
- index of an array procesing
- java syntax
- unity how to make a gameobject slowly look at a position
- how to create gravity in java
- java replace element in list
- classes in java
- java random number
- java round double to 2 decimal places
- split every character in string into array java
- crit chance in java
- how to compare two maps in java
- how to scan a character in java
- null pointer exception java
- java print syntax
- take a value from keyboard java
- change the value in a hashtable java
- java override equals and hashcode
- adding an element to the end of a linked list java
- how to open a text file in java
- arraylist add method
- set password visible in android