I have some trouble with Eclipse I guess.
I want to run my factorial program and it compiles but doesn’t do anything else. Meaning no error message, no warning, etc…
Here is the code maybe you guys can tell me if the mistake is in the code or my eclipse needs some fix.
Or it is the big numbers?
import java.math.BigInteger;
public class FactorialTrailingZeros {
public static void main(String[] args) {
int N = 60;
System.out.println(factorial(N));
System.out.println(getZeros(factorial(N)));
}
public static BigInteger factorial(int N){
BigInteger fact = new BigInteger("1");
for(BigInteger t = BigInteger.valueOf(1);
t.compareTo(BigInteger.ZERO) <= N;
t.add(BigInteger.ONE)){
//bi1 = bi1.multiply(bi2);
fact = fact.multiply(t);//multiply BigIntegers
}
return fact;
}
public static int getZeros(BigInteger C){
int count = 0;
while(C.mod(BigInteger.TEN) == BigInteger.ZERO){ //while the last digit is not different than 0 don't stop
C = C.divide(BigInteger.TEN); //divide by 10 each time so we get a 10 times smaller number 100 -> 10
count++;
}
return count;
}
}