求水仙花数的
来源:互联网 发布:常州梦骑士淘宝店 编辑:程序博客网 时间:2024/04/28 13:05
int length=4;//一个4位数的水仙花的和
int min=(int) Math.pow(10, length-1);//求4位数中最小的数
int max=(int)( Math.pow(10, length))-1;//求4位数中最大的数
System.out.println(min+" "+max); //输出4位数中 最小数和最大数
int temp=0;
int sum=0;
for(int i=min;i<=max;i++){
temp=i;
while(temp>=1){
sum += (int) Math.pow( temp%10,length);
temp=temp/10;
//System.out.println(temp);
}
if(i == sum)
System.out.print(i+" ");
sum=0;
}
}
}
int min=(int) Math.pow(10, length-1);//求4位数中最小的数
int max=(int)( Math.pow(10, length))-1;//求4位数中最大的数
System.out.println(min+" "+max); //输出4位数中 最小数和最大数
int temp=0;
int sum=0;
for(int i=min;i<=max;i++){
temp=i;
while(temp>=1){
sum += (int) Math.pow( temp%10,length);
temp=temp/10;
//System.out.println(temp);
}
if(i == sum)
System.out.print(i+" ");
sum=0;
}
}
}
0 0
- 求水仙花数的
- 求三位数的水仙花数
- 求所有的水仙花数
- 求水仙花数的算法
- 求所有的水仙花数
- 求三位数的水仙花数
- 求水仙花数和回文的判断
- 求1000以内的水仙花数
- 求21位数的水仙花数
- 求21位数的水仙花数
- 【求水仙花数】的算法实现
- 求1-10000之间的水仙花数
- 求100以内的素数 水仙花数
- C#求三位数的水仙花数
- 求100到999的水仙花数
- 求1000以内的水仙花数
- 求21位数的水仙花数
- 求1000以内的所有水仙花数
- eMMC Mandatory Boot和Alternative Boot
- 计算机论文写作提纲
- Hadoop 实例10 Join讲解3: 将人员的地址ID完善成为地址名称,输出格式要求:人员Id,姓名,地址 ----优化方案
- 第三十一天 ViewPager(带小圆点的图片左右循环滑动)、Fragment
- hdu 3549 a flow problem 的多种解法
- 求水仙花数的
- FASTCGI与CGI解释器的区别,及其工作原理
- HDU 5428-The Factor(分解质因子)
- JAVA学习——多线程通信
- Xenu-死链接检测工具
- 文件上传
- supervisor安装整理
- VC短信接口开发经验及具体开发实现
- SAE云应用Counter工具实现访问计数