猿问

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

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));

    }

}


慕尼黑8549860
浏览 210回答 3
3回答

幕布斯6054654

取最后一位数BigInteger除以 10 时的余数System.out.println(f.remainder(BigInteger.TEN));
随时随地看视频慕课网APP

相关分类

Java
我要回答