当前位置:网站首页>查找水仙花数-for循环实践
查找水仙花数-for循环实践
2022-04-23 14:12:00 【Zinksl】
:::info
根据 遗忘曲线:如果没有记录和回顾,6天后便会忘记75%的内容
读书笔记正是帮助你记录和回顾的工具,不必拘泥于形式,其核心是:记录、翻看、思考
:::
水仙花数(Narcissistic number)也被称为超完全数字不变数(pluperfect digital invariant, PPDI)、自恋数、自幂数、阿姆斯壮数或阿姆斯特朗数(Armstrong number),水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身。
案例需求
需求1 找出所有水仙花数
1 通过for循环筛选出三位数
2 通过if按照水仙花数概念,晒出水仙花数
//for循环找出水仙花数
for (int i=100;i<=999;i++){
int ge,shi,bai; //定义各位、十位、百位变量准备后续操作
ge = i%10;
shi = i/10%10;
bai = i/100;
//用if对水仙花数条件进行筛选
if (i==(ge*ge*ge+shi*shi*shi+bai*bai*bai)){
System.out.println("水仙花数:"+i);
}
}
结语
文中如有问题,欢迎指正,欢迎大家在评论区讨论
看到这儿了,就点个赞再走吧ღ( ´・ᴗ・` )比心
版权声明
本文为[Zinksl]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Zinkse/article/details/123893364
边栏推荐
猜你喜欢

顺序表的操作,你真的学会了吗?

API Gateway/API 网关(四) - Kong的使用 - 集成Jwt和熔断插件

Use the executors class to quickly create a thread pool

KVM learning resources

ThreadGroup ThreadGroup implémente l'interface threadfactory en utilisant la classe Introduction + Custom thread Factory

TLS/SSL 协议详解 (30) SSL中的RSA、DHE、ECDHE、ECDH流程与区别

XX project structure notes

循环队列的基本操作(实验)

MySQL数据库讲解(九)

krpano全景之vtour文件夹和tour
随机推荐
krpano全景之vtour文件夹和tour
DP energy Necklace
squid代理
uni-app消息推送
STD:: map and STD:: vector memory free
JS progress bar, displaying the loading progress
翻牌效果
LLVM - 生成加法
MySQL同步Could not find first log file name in binary log index file错误
SED 学以致用
Redis cluster 原理
Pass in external parameters to the main function in clion
gif转为静态图片处理
如何轻松做好一个项目
如何5分钟上手使用OCR
How does void * exist?
redis数据库讲解(四)主从复制、哨兵、Cluster群集
网页自适应,等比缩放
std::map 和 std::vector 内存释放
Logback logger and root
