前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【每天一道编程系列-2018.2.11】(Ans)[补]

【每天一道编程系列-2018.2.11】(Ans)[补]

作者头像
yesr
发布2019-03-14 12:54:22
2550
发布2019-03-14 12:54:22
举报
文章被收录于专栏:leetcode_solutionsleetcode_solutions

【题目描述】

The number of daffodils refers to an n-digit number (n≥3), the sum of the n-th power of the digits in each of its digits, etc. On its own. (For example: 1 ^ 3 + 5 ^ 3 + 3 ^ 3 = 153). Program to find out all three daffodils.

【题目翻译】

水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153)。编程求出所有三位的水仙花数。

【本题答案】

代码语言:javascript
复制
/**
 * @author yesr
 * @create 2018-02-12 下午9:51
 * @desc
 **/
public class Test0211 {
    public static void main(String[] args) {
        for(int num=100;num<1000;num++){
            if(sxh(num)){
                System.out.println(num);
            }
        }
    }
    //判断一个数是不是水仙花数
    private static boolean sxh(int num){
        int b=num/100;
        int s=num%100/10;
        int g=num%10;
        return Math.pow(b, 3)
                + Math.pow(s, 3)
                + Math.pow(g, 3) == num;
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018年02月12日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档