js中求水仙花数
2024-08-28 12:21:19
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
//水仙花数
for (var num = 100; num <= 999; num++) { var str = num.toString();
var res1 =Number(str.slice(0,1)) //百位 或者用charAt(0)
var res2 =Number(str.slice(1,2)) //十位 或者用charAt(1)
var res3 =Number(str.slice(2,3)) //个位 或者用charAt(2) var sumcube = Math.pow(res1,3)+Math.pow(res2,3)+Math.pow(res3,3); //立方和
num = res1*100+res2*10+res3; //这个数
if(sumcube == num){
console.log(num);
}
}
</script>
</head>
<body> </body>
</html>
最新文章
- Eclipce结合Ant进行编译、打包、传输、运行
- 关于break和continue的区别
- Python下划线与命名规范
- MySQL两种表存储结构MyISAM和InnoDB的性能比较测试
- Force StyleCop to Ignore a File
- Java基础之创建窗口——使用BoxLayout管理器(TryBoxLayout4)
- Spring中使用Jcaptcha实现校验码验证
- NSS_09 gridpanel中的actioncolumn事件
- MarkDown中锚点的使用
- 求模和求余(附加C语言实现)
- 重启IIS报错:IIS 服务或万维网发布服务,或者依赖这 服务可能在启动期间发生错误或者已禁用
- 警告:‘xxxx’ 将随后被初始化
- 轻狂写的桌面日历秀NSIS脚本供大家参考学习
- Pass和ClassPath变量配置
- Nginx和php是怎么通信的?
- 【Linux】安装多个JDK并切换
- POSTMAN发送WebService接口
- C++ Com控件调用
- switch-case最容易忽视的一点
- 通过监控Nginx日志来实时屏蔽高频恶意访问的IP
热门文章
- bzoj 2286(虚树+树形dp) 虚树模板
- 【二分图】【并查集】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem L. Canonical duel
- 网络编程之tcp五层模型
- android 关于Make sure the plugin is properly configured问题的解决办法
- 详解React的生命周期
- Ubuntu下查看APT安装的软件安装路径和版本
- c#版 mqtt 3.1.1 client 实现
- Inno Setup入门(十九)——Inno Setup类参考(5)
- Struct2_使用Ajax调用Action方法并返回值
- attribute用法