class Demo {
public static void main(String[] args) {
//这是求水仙花数的和
for (int i =100; i <=999;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);
}
}
//求水仙花数共有多少个
int count =0;
for (int i=100;i<=999 ;i++) {
int ge = i% 10;
int shi= i/10%10;
int bai = i/10/10%10;
if (i==ge*ge*ge+shi*shi*shi+bai*bai*bai) {
count++;
}
}
System.out.println("count="+count);
}
}
|
|