Java求大数阶乘

代码:


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

public class Main {
    
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        BigInteger num = new BigInteger("1");
        BigInteger ii = new BigInteger("1");

        int n = scan.nextInt();

        for (int i = 0; i < n; i++) {
            num = num.multiply(ii);
            ii = ii.add(new BigInteger("1"));
        }

        System.out.println(n + "!=" + num);
    }
}
_AD
发布了9 篇原创文章 · 获赞 0 · 访问量 327

猜你喜欢

转载自blog.csdn.net/weixin_43553153/article/details/104034271
今日推荐