题目一:求1000!的结果中包含多少个0?注:1000! = 1×2×3×4×5×...×999×1000
public class Demo05{
public static void main(String[] args){
int n = 1000;
int a = 0;
System.out.print(n+"的阶乘后面有:");
while(n!=0){
a=a+(n/5);
n=n/5;
}
System.out.println(a+"个0");
}
}
题目二:用代码证明,在try中写了return,后面又写了finally,是先执行return还是先执行fianlly?
public class Demo05{
public static void main(String[] args)throws Exception{
System.out.println(method());
}
public static String method()throws Exception{
try{
System.out.println("执行try");
return "执行try的return";
}
catch(Exception e){
}finally{
System.out.println("执行finally");
}
return "";
}
} |