Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.math.BigInteger;
- public class Factorial {
- // 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
- {
- Scanner input = new Scanner(System.in);
- System.out.print("Enter number : ");
- int n = input.nextInt();
- System.out.println(factorial(n));
- }
- }
Add Comment
Please, Sign In to add comment