java循环练习:水仙花数
2016-04-10 14:53
417 查看
package practiceGO; /* *5、算水仙花数(100-999):表示三位数的数字,个位的三次方+十位的三次方+百位的三次方=这个数本身 */ public class Cto { public static void main(String[] args) { int first,second,third; for(int i=100; i<=999; i++){ first = (i/100); second = (i-first*100)/10; third = i%10; if (Math.pow(first, 3)+Math.pow(second, 3)+Math.pow(third, 3) == i) { System.out.println(i+"是水仙花数"); } } } }运行结果:
153是水仙花数 370是水仙花数 371是水仙花数 407是水仙花数
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树