希望讲的详细一点,如果讲方便,写一个范例最好,谢谢

解决方案 »

  1.   

    /*
    * 所谓 "水仙花数 "是指一个三
    * 位数,其各位数字立方和等于该数本身。例如:153是一个 "水仙
    * 花数 ",因为153=1的三次方+5的三次方+3的三次方。
    */
    public class Test {
    public static void main(String[] args) {
    daffodilNumber();
    }
    public static void daffodilNumber(){
    int sum=0, one=0, two=0,three=0;
    for(int i=100;i<=999;i++){
    one=i/100;//取得百位数
    two=(i%100)/10;//取得十位数
    three=i%10;//取得个位数
    sum=one*one*one+two*two*two+three*three*three;//计算每位数三次方的相加之和
    if(i==sum){
    System.out.println(i+"是水仙花数");
    }
    }
    }
    }