```
public class Solution {
public int trailingZeroes(int n) {
int power = 5;
int amount = 0;
int num5 = 0;
int num2 = 0;
while(n >= power){
amount = n / power;
num5 += amount;
power = power * 5;
}
power = 2;
while(n >= power){
amount = n / power;
num2 += amount;
power = power * 2;
}
return Math.min(num5, num2);
}
}
```

This code works well except for very large integer, e.g. for a 9 digits number.

It will throw a / by zero exception on **amount = n / power** in the second loop.

I don't understand why it happens. Please help.