public class Test5 {
//计算能够被n整除的个数
static int getDiv(int n){
int temp = 0;
for(int i = 1; i <= 1000; i++){
if(i%n == 0){
temp++;
}
}
return temp;
}
public static void main(String[] args) {
int n = 5;
int num = 0;
//遍历5,25,125,625……不超过1000
for(int i = n; i <= 1000; i*=5){
num += getDiv(i);
}
System.out.println("!1000的末尾有"+num+"个零.");
}
} |