水仙花数
public class Main {
public static void main(String[] agrs){
int count = 1;
int sum = 0;
for(int i = 100; i <= 1000; i++){
if(isFlowerNumber(i)){
System.out.printf("第%d个水仙花数:%d%n",count,i);
count++;
sum += i;
}
}
System.out.printf("水仙花数总和为:%d%n",sum);
}
public static boolean isFlowerNumber(int n){
int pow = 3;
int sum = 0;
int temp = n;
while(n != 0){
int num = n % 10;
sum += (int)Math.pow(num,pow);
n /= 10;
}
return sum == temp;
}
}