求3位的水仙花数

水仙花数(Narcissistic number)也被称为超完全数字不变数(pluperfect digital invariant, PPDI)、自幂数、阿姆斯壮数或阿姆斯特朗数(Armstrong number),水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身(例如:1^3 + 5^3+ 3^3 = 153)。
Q:求所有水仙花数量。水仙花是指一个3位数,他的每个位上的数字的3次幂之和等于它本身
A:
具体代码如下 代码.

//public class NumberOfDaffodilsTest {
    public static void main(String[] args) {
        System.out.println("水仙花数:");
        for (int i = 100 ; i < 1000 ; i++) {
            int a = (int) Math.pow(i / 100 , 3);
            int b = (int) Math.pow(((i / 10) -((i / 100) * 10)) , 3);
            int c = (int) Math.pow(i - ((i / 10) * 10) , 3);
            if(i == a + b + c){
                System.out.print(i +" ");
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/Turbococo/article/details/108013994