您的位置:首页 > 编程语言 > Java开发

大数 N!——java

2015-09-25 20:34 274 查看
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


言简意赅,即求n的阶乘。

附java代码,记之。

import java.util.*;
import java.math.*;
public class Main{
public static void main(String[] args){
Scanner cin=new Scanner(System.in);
int a;
while(cin.hasNextInt()){
a=cin.nextInt();
BigInteger b=BigInteger.ONE;
for(BigInteger i=BigInteger.ONE; i.compareTo(BigInteger.valueOf(a))!=1; i=i.add(BigInteger.ONE)){
b=b.multiply(i);
}
System.out.println(b);
}
cin.close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: