题目:
解决方法:
package com.algorithm.java.blueBirdge; import java.util.Scanner; public class zero { public static int zero(String a){ int sum=0; for(int i=0;i<a.length();i++){ char c=a.charAt(i); if(c==‘0‘) sum+=1; } return sum; } public static String jiech(int n){ long chengji =1; for(int i=1;i<=n;i++){ chengji=chengji*i; } String s = String.valueOf(chengji); return s; } public static void main(String[] args){ Scanner read =new Scanner(System.in); int n=read.nextInt(); //System.out.println(jiech(11)); String as=jiech(n); System.out.println(zero(as)); } }
但是问题是,不能先计算阶乘,应该直接计算后面的0,若计算阶乘,则超出范围。