1057 N的阶乘(Java高精度乘单精度)

N的阶乘

题目链接:http://www.51nod.com/Challenge/Problem.html#problemId=1057
在这里插入图片描述

解题思路:

Java大数类:BigInteger方法

代码如下:

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    
    
	public static BigInteger jc(int n) {
    
      //计算阶乘
		BigInteger s = BigInteger.ONE;
		for (int i = 2; i <= n; i++)
			s = s.multiply(new BigInteger(Integer.toString(i)));
		return s;
	}
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		System.out.println(jc(n));
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_45894701/article/details/114952365