当前位置:网站首页>查找水仙花数-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
边栏推荐
猜你喜欢
Processing MKDIR: unable to create directory 'AAA': read only file system
C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【1】
About the configuration and use of json5 in nodejs
Tongxin UOS php7 2.3 upgrade to php7.0 two point two four
XX project structure notes
MySQL-InnoDB-事务
在Clion中给主函数传入外部参数
A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios
openstack理论知识
TUN 设备原理
随机推荐
JS recursion (1)
基础正则表达式
ie8 浏览器提示是否 阻止访问js脚本
grep无法重定向到文件的问题
百度笔试2022.4.12+编程题目:简单整数问题
setcontext getcontext makecontext swapcontext
man man随记和crontab的@reboot用法
yml引用其他变量
统信UOS卸载php7.2.24,安装php7.4.27 ;卸载再安装为PHP 7.2.34
mysql 5.1升级到5.66
JS format time
Processing MKDIR: unable to create directory 'AAA': read only file system
预览CSV文件
Visio画拓扑图随记
About the configuration and use of json5 in nodejs
API Gateway/API 网关(三) - Kong的使用 - 限流rate limiting(redis)
ansible及常用模块的使用
浅谈skiplist在LevelDB的应用
TUN 设备原理
Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface