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 6import java.math.BigDecimal; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); while(s.hasNextInt()){ BigDecimal b = BigDecimal.ONE; int n = s.nextInt(); for(int i=1;i<=n;i++){ b = b.multiply(BigDecimal.valueOf(i)); } System.out.println(b); } } }
该博客介绍了如何使用JAVA解决杭电1042题目的需求,即计算并输出不超过10000的整数阶乘。博主通过创建BigDecimal对象并利用循环进行大数乘法运算,实现了大数阶乘的计算,并给出了样例输入输出。
696

被折叠的 条评论
为什么被折叠?



