Factorial of N
Subject link: http://www.51nod.com/Challenge/Problem.html#problemId=1057
Problem-solving ideas:
Java large number classes: BigInteger method
code show as below:
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static BigInteger jc(int n) {
//计算阶乘
BigInteger s = BigInteger.ONE;
for (int i = 2; i <= n; i++)
s = s.multiply(new BigInteger(Integer.toString(i)));
return s;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
System.out.println(jc(n));
}
}