Как я мог показать только конкретную цифру вывода? Как я могу удалить 0 из bigInteger?
Мой пример:
Имея задачу показать последнее число факториала числа, которое не равно 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));
}
}
Пример vol2 --> Здесь мне нужно решение для удаления 0 из biginteger:
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 из числа? Это был бы самый простой способ решить мою проблему