水仙花

 

153 是水仙花数
370 是水仙花数
371 是水仙花数
407 是水仙花数

 

for i in range(100, 1001):
    num_str = str(i)
    if i == int(num_str[0])**3 + int(num_str[1])**3 + int(num_str[2])**3:
        print("%d 是水仙花数" % i)

 

public class Flower {
    public static void main(String[] args) {
        for(int i = 100; i < 1000; i++) {
            int bai = i / 100;  //百位数
            int shi = i / 10 % 10;  //十位数
            int ge = i % 10;  //个位数
            
            if(i == bai * bai * bai + shi * shi * shi + ge * ge * ge){
                System.out.println(i + " 是水仙花数");
            }
        }
    }

}

 

posted @ 2020-04-24 14:50  CherryYang  阅读(110)  评论(0)    收藏  举报