HDOJ 1042 N!(大数阶乘JAVA)

2021-01-20 16:25:47 浏览数 (1)

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

JAVA 大数轻松AC!

代码语言:javascript复制
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()){
            BigDecimal n = sc.nextBigDecimal();
            BigDecimal m=new BigDecimal(1);
            for(int i=2;i<=n.intValue();i  ){
                m = m.multiply(new BigDecimal(i));
            }
            System.out.println(m.toPlainString());
        }
    }

}

0 人点赞