要求:输出从1-1000之间的所有水仙花数
实现代码如下:
package Java_004水仙花数;
public class main{
public static void main(String[] args){
System.out.println("output:please num");
int number = 100;
int i, j, k;
for (int sum; number<1000; number++){
i=number/100;
j=(number-i*100)/10;
k=number-i*100-j*10;
sum=i*i*i+j*j*j+k*k*k;
if (sum==number)
System.out.println(number+" is a dafodil number! ");
}
}
}