当前位置:网站首页>查找水仙花数-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
边栏推荐
猜你喜欢
MySQL数据库讲解(七)
进入新公司,运维工程师从下面这几项了解系统的部署
asp.net使用MailMessage发送邮件的方法
Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)
KVM learning resources
Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface
01-nio basic ByteBuffer and filechannel
微信小程序将原生请求通过es6的promise来进行优化
Storage path of mod subscribed by starbound Creative Workshop at Star boundary
Processing MKDIR: unable to create directory 'AAA': read only file system
随机推荐
MySQL-InnoDB-事务
JDBC details
tcp_diag 内核相关实现 1 调用层次
获取线程返回值Future接口与FutureTask类使用介绍
Redis数据库讲解(一)
在Clion中给主函数传入外部参数
Installation and use of postman pit
MySQL lock database lock
一些小小小小记录~
Redis cluster 原理
贷款市场报价利率(LPR)与贷款基准利率介绍
js 抛物线运动方法封装
MYSQL一种分表实现方案及InnoDB、MyISAM、MRG_MYISAM等各种引擎应用场景介绍
进入新公司,运维工程师从下面这几项了解系统的部署
js 键值判断
MySQL同步Could not find first log file name in binary log index file错误
DP energy Necklace
A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios
Operation instructions of star boundary text automatic translator
js 递归(1)