public class learn2 {
public static void main(String[] args) {
int count =0;//定义水仙花的个数
for (int i =100; i<=999; i++)
{
int g = i%10;
int s = i/10%10;
int b = i/100%10;
if (i == b*b*b +s*s*s +g*g*g){
count+=1;
System.out.println(i);
}
}
System.out.println("一共有"+count+"只水仙花");
}
}
结果展示