求100-1000之间的水仙花数
例:每位数的立方相加等于原数371=3×3×3+7×7×7+1×1×1
public void daffodil() {
int count = 0;
for (int i = 100; i < 1000; i++) {
int ge = i % 10;
int shi = i / 10 % 10;
int bai = i / 10 / 10 % 10;
if ((ge * ge * ge) + (shi * shi * shi) + (bai * bai * bai) == i) {
System.out.println( i );
count++;
}
}
System.out.println( "水仙花一共有" + count + "个" );
}
网友评论