为了账号安全,请及时绑定邮箱和手机立即绑定

我想取出 JAVA 中 BigInteger 中存储的大数的最后一位

我想取出 JAVA 中 BigInteger 中存储的大数的最后一位

慕尼黑8549860 2021-06-10 18:15:55
import java.math.BigInteger;import java.util.Scanner;public class LastFact{    // Returns Factorial of N    static BigInteger factorial(int N)    {        // Initialize result        BigInteger f = new BigInteger("1"); // Or BigInteger.ONE        // Multiply f with 2, 3, ...N        for (int i = 2; i <= N; i++)            f = f.multiply(BigInteger.valueOf(i));        return f;    }    // Driver method    public static void main(String args[]) throws Exception    {        int N = 300;        System.out.println(factorial(N));    }}
查看完整描述

3 回答

?
幕布斯6054654

TA贡献1876条经验 获得超7个赞

取最后一位数BigInteger除以 10 时的余数

System.out.println(f.remainder(BigInteger.TEN));


查看完整回答
反对 回复 2021-06-23
  • 3 回答
  • 0 关注
  • 214 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号