显示输出的特定数字 // 从 bigInteger 中删除 0

Shows specific digit of the output // deleting 0's from bigInteger

我怎样才能只显示输出的特定数字? 如何从 bigInteger 中删除 0?

我的例子:

有一个任务显示数字的阶乘的最后一个不为 0 的数字。

Example:
1! = 1
2! = 2
3! = 6
4! = 4
5! = 2
6! = 2

现在它只显示阶乘。

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

public class Main{
    // 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
    {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(factorial(n));
    }
}

Example vol2 --> 这里我需要一个从 biginteger 中删除 0 的解决方案:

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

public class Main{
    // 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
    {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        BigInteger a = (factorial(n));
        BigInteger b, c;
        c = new BigInteger("10");
        b = a.mod(c);
        System.out.println(b);
        System.out.println(a);
    }
}

有没有一种简单的方法可以从数字中删除所有的 0?那将是解决我的问题的最简单方法

您可以将数字转换为字符串并删除零。然后你把它放回 BigInteger:

public static BigInteger removeZeroes(int i) {
    return new BigInteger(String.valueOf(i).replace("0", ""));
}