当前位置:网站首页>查找水仙花数-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
边栏推荐
- After entering the new company, the operation and maintenance engineer can understand the deployment of the system from the following items
- mysql 5.1升级到5.67
- sar命令详解
- 关于UDP接收icmp端口不可达(port unreachable)
- About the configuration and use of json5 in nodejs
- rsync+inotify远程同步
- tcp_diag 内核相关实现 1 调用层次
- grep无法重定向到文件的问题
- 01-nio basic ByteBuffer and filechannel
- How does void * exist?
猜你喜欢

MySQL数据库讲解(九)

Man man notes and @ reboot usage of crontab

C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【1】

正则表达式

MySQL数据库讲解(七)

C语言知识点精细详解——数据类型和变量【1】——进位计数制

After entering the new company, the operation and maintenance engineer can understand the deployment of the system from the following items

关于UDP接收icmp端口不可达(port unreachable)

处理 mkdir:无法创建目录“aaa“:只读文件系统

Logback logger and root
随机推荐
循环队列的基本操作,你学会了吗?
Wechat applet rotation map swiper
STD:: map and STD:: vector memory free
About the configuration and use of json5 in nodejs
void*是怎样的存在?
Redis源码分析之PSYNC同步
xx项目架构随记
Pass in external parameters to the main function in clion
Preview CSV file
mysql 5.1升级到5.67
Uni app message push
解决ssh配置文件优化以及连接慢的问题
拨开云雾synchronized使用五种方式介绍
ie8 浏览器提示是否 阻止访问js脚本
Arrays类的使用案例
js 递归(1)
After entering the new company, the operation and maintenance engineer can understand the deployment of the system from the following items
flannel 原理 之 子网划分
LLVM - 生成for循环
Introduction to loan market quotation interest rate (LPR) and loan benchmark interest rate
