首页 > 其他 > 详细

求100到999之内的水仙花数

时间:2017-11-11 13:46:13      阅读:200      评论:0      收藏:0      [点我收藏+]
 /**
     * 水仙花数
     */
	public static void findDaffodilNumbe() {
		for (int i = 100; i < 999; i++) {
			int data = 0;
			List<Integer> list = getList(i);
			for (int j = 0; j < list.size(); j++) {
				data += (int)Math.pow(list.get(j), 3);
			}
			if (data == i) {
				System.out.print(data + "  ");
			}
		}
		
		
	}
	
	public static List<Integer> getList(int n) {
		List<Integer> list = new ArrayList<Integer>();
		list.add(n % 10);
		list.add(n / 10 % 10);
		list.add(n / 100);
		return list;
		
	}

  

求100到999之内的水仙花数

原文:http://www.cnblogs.com/wangxiaowang/p/7818771.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!