03_for循环例子

求水仙花数

三位数的个位、十位、百位的立方和等于自己

package com.it.learn.switch_test;

public class ForTest {
    public static void main(String[] args) {
        for (int i = 100; i <= 999; i++) {
            int ge = i % 10;
            int shi = i % 100 / 10;
            int bai = i / 100;
            if (Math.pow(ge, 3) + Math.pow(shi, 3) + Math.pow(bai, 3) == i) {
                System.out.println(i + "是水仙花数");
            }
        }
    }
}
posted @ 2023-07-06 10:43  徐林俊  阅读(4)  评论(0编辑  收藏  举报