I am trying the FCTRL exercise and am getting some good results for the first couple of tests after this mine results fall behind. For 60 I get 14 trailing zeroes for 100 I get 24 but for 1024 I get 245 and for 23456 I get 5666.
Here is my code:
public class TrailingZeroesMultipleOfFive {
public static void main(String[] args) {
//variables
int N;
int factor = 5;
int i = 1;
int sum = 0;
//get input from console
//Scanner scan = new Scanner(System.in);
//N = scan.nextInt();
N = 23456;
while(N >= 1){
N /= factor; //divide by factor
sum += N; //add the division result to sum
factor = (int) Math.pow(factor,i++); //next loop N will be divided by the next power of 5
}
System.out.println(sum);
}
}
Do you think the problem is in the pow function and the casting?