Factorial of large numbers

In this example, You learn about Factorial of Large Number in java program. 

Here you learn factorial of large numbers in Java, You are given a number and the task of the program to find factorial of large number.

Factorial of Large Number Program in Java

import java.util.Scanner;
import java.math.BigInteger;

public class BigFactorial
{
 public static void main(String args[])
 {
    int n, c;
    BigInteger inc = new BigInteger("1");
    BigInteger fact = new BigInteger("1");
    Scanner input = new Scanner(System.in);
    System.out.println("Input an integer");
    n = input.nextInt();
    for (c = 1; c <= n; c++) {
        fact = fact.multiply(inc);
        inc = inc.add(BigInteger.ONE);
    }
    System.out.println(n + "! = " + fact);
 }
}
Output

Input an integer 
50

50! = 30414093201713378043612608166064768844377641568960512000000000000

If you have any doubts, Please let me know

Previous Post Next Post

Contact Form