Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
Input
One N in one line, process to the end of file.
Output
For each N, output N! in one line.
Sample Input
1
2
3
Sample Output
1
2
6
代码:
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
System.out.println(fun(n));
}
}
public static BigDecimal fun(int n) {
BigDecimal s = new BigDecimal(1);
for (int i = 1; i <= n; i++) {
BigDecimal a = new BigDecimal(i);
s = s.multiply(a);
}
return s;
}
}