N!
Problem Description
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
一个简单的大数练习
AC代码:
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 num = sc.nextInt(); BigDecimal result = BigDecimal.valueOf(1); for (int i = 1; i <= num; i++) { result = result.multiply(BigDecimal.valueOf(i)); } System.out.println(result); } } }