N! Java大數 水過
阿新 • • 發佈:2018-11-13
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
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO 自動生成的方法存根 Scanner cin = new Scanner(System.in); while (cin.hasNext()) { int n = cin.nextInt(); BigInteger sum = new BigInteger("1") ; int i=1; while (i<=n) { sum = sum.multiply(BigInteger.valueOf(i)); i++; } System.out.println(sum); } } }