Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.math.BigInteger;
- public class BigFactorial {
- /** Program: BigFactorial.java
- * Purpose: Find n! up to 10000! using Big Integers
- * Creator: Chris Clarke
- * Created: 16.07.2012
- */
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- System.out.print( "Enter a number (max 10000): ");
- int n = keyboard.nextInt();
- BigInteger bigInt = new BigInteger (""+n);
- System.out.println( "The factorial of "+n+" = "+n+"! = "+factorial( bigInt));
- }
- public static BigInteger factorial( BigInteger b) {
- return b.equals(BigInteger.ONE)?
- BigInteger.ONE:
- b.multiply( factorial( b.subtract( BigInteger.ONE)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement