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

【题目描述】


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)。编程求出所有三位的水仙花数。






【本题答案】


/**
 * @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;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值