水仙花数定义:
- 一定是3位数
- 每一位的立方,加起来恰好是这个数本身,比如153=111+555+333
寻找所有的水仙花数
public class HelloWorld {
public static void main(String[] args){
int hundred=0;
int tens=0;
int single=0;
System.out.println("所有的水仙花数有:");
for (int i=100;i<1000;i++){
hundred = i/100;
tens = (i-hundred*100)/10;
single = (i-hundred*100-tens*10)/1;
if (i == hundred*hundred*hundred + tens*tens*tens + single*single*single){
System.out.println(i);
}
}
}
}