/**
* @param args
* 需求:求出1000的阶乘所有零和尾部零的个数,不用递归做
*/public static void multiply(){
//int multiply = 1;
BigInteger multiply = new BigInteger("1");
for(int i=1;i<=1000;i++){
multiply = multiply.multiply(new BigInteger(i+""));
}
System.out.println(multiply);
String str = multiply.toString();
StringBuilder sb = new StringBuilder(str);
str = sb.reverse().toString();
int count = 0;
for(int i=0;i<str.length();i++){
if('0'==str.charAt(i)){
count++;
}else{
break;
}
}
System.out.println(count);
} |
|