java阶乘计算获得结果末尾0的个数代码实现
时间:2022-11-30 00:01:02
看到题目后,分析了下, 10的阶乘就已经很大了。计算出来再得到这个末尾的0的个数,完全不现实,即使实现了也是很麻烦的。
后来想某个数的阶乘中乘积有5结尾的数字的时候就应该在结果的末尾产生一个0.
付诸实现,测试了几个, 没出错。
贴出来, 大家看看, 有问题了及时指教:
/**
* 求1000~10000之间的数n的阶层并计算所得的数n!末尾有多少个0?
*/
public static void test2(int number){
int count = number/5;
System.out.println(count);
}
又复习了下数学知识,上面的计算应该是不对的。
应该写成下面这样,每到5的倍数时候会+1 。
int x = 10000;
while (x>0)
{
count = count + x / 5;
x = x / 5;
}
System.out.println(count);
标签:java,阶乘计算
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android Studio3.0新特性及安装图文教程
2021-06-21 02:11:48
![](https://img.aspxhome.com/file/2023/7/120047_0s.jpg)
spring缓存自定义resolver的方法
2021-05-30 17:07:56
![](https://img.aspxhome.com/file/2023/9/76259_0s.png)
C# 添加、修改以及删除Excel迷你图表的实现方法
2023-04-06 22:07:27
![](https://img.aspxhome.com/file/2023/6/81046_0s.png)
Android设置项目为系统APP方法
2022-11-16 08:55:02
Spring Boot如何优化内嵌的Tomcat示例详解
2023-11-13 17:52:53
Android开源库自定义相机模块
2023-08-31 04:21:59
![](https://img.aspxhome.com/file/2023/5/129025_0s.jpg)
浅谈java中对集合对象list的几种循环访问
2022-02-11 02:32:33
SpringMVC接收复杂集合对象(参数)代码示例
2023-01-29 18:33:51
Java多线程 Callable、Future 和FutureTask
2023-07-24 08:09:23
![](https://img.aspxhome.com/file/2023/2/78872_0s.png)
Spring整合WebSocket应用示例(上)
2023-05-05 10:09:21
java的泛型你真的了解吗
2022-07-25 09:40:06
![](https://img.aspxhome.com/file/2023/5/60355_0s.jpg)
如何通过JVM角度谈谈Java的clone操作
2023-10-13 09:54:40
![](https://img.aspxhome.com/file/2023/1/85881_0s.png)
举例讲解Java的Spring框架中AOP程序设计方式的使用
2022-11-21 21:22:15
android AudioRecorder简单心得分享
2021-12-13 08:23:46
Spring Security短信验证码实现详解
2023-07-04 22:27:07
![](https://img.aspxhome.com/file/2023/4/132214_0s.png)
C#开发Windows服务实例之实现禁止QQ运行
2023-04-13 03:29:29
![](https://img.aspxhome.com/file/2023/6/83296_0s.jpg)
java编程实现根据EXCEL列名求其索引的方法
2022-04-24 03:08:03
mybatis中的缓存问题解析
2023-07-27 20:01:59
![](https://img.aspxhome.com/file/2023/0/103820_0s.png)
jenkins+Maven从SVN上构建项目的方法
2022-07-09 04:42:37
![](https://img.aspxhome.com/file/2023/2/61582_0s.png)
Java工程中使用Mybatis (工程结合Mybatis,数据结合Swing使用))
2023-05-27 11:52:38
![](https://img.aspxhome.com/file/2023/8/78038_0s.png)