水仙花数
水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身
(例如:1^3 + 5^3+ 3^3 = 153)。
public static void main(String[] args) {
int count =0;
for (int x=100;x<1000;x++){
int a=x%10;
int b=x/10%10;
int c=x/100%10;
if ((a*a*a+b*b*b+c*c*c)==x){
System.out.println(x);
count++;
}
}
System.out.println("共有:" + count + "个");
}