求n的阶乘值(n!)尾部有多少个连续的0
String b=""+a;
for(int i=0;i<b.length();i++)
{
if(i<b.length()-1)
{
if(b.charAt(i)=='0'&&b.charAt(i+1)=='0')
{
total++;
}
}
}
System.out.print(total);
import java.util.Scanner;
import java.math.BigInteger;
public class Cal0atEndsByBigInteger1
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner rd=new Scanner(System.in);
int total=0;
System.out.println("请输入起始数:");
int n=rd.nextInt();
int m;
do
{
System.out.println("请输入截止数:");
m=rd.nextInt();
}while(m<n);
String product=multiplyNM(n,m);
int length=product.length();
for(int i=0;i<product.length();i++)
{
char c=product.charAt(length-i-1);
if(c!='0')
{
break;
}
else
{
total++;
}
}
System.out.print(n+" 到"+m+" 连乘 = "+product+" 后面有"0" "+total+" 个");
}
//用大数字计算阶乘,并返回字符串
//
public static String multiplyNM(int n,int m)//返回字符串
{
BigInteger sum=new BigInteger("1");
for(int i=n;i<=m;i++)
{
sum=sum.multiply(new BigInteger(""+i));
}
return sum.toString();
}
}