1 package com.xt.homework.hw09; 2 /** 3 * 4 * 6. 輸出所有水仙花數(如果一個3位正整數的各 5 * 個位數立方和等於這個數本身,稱為水仙花數)。 6 * 7 * @author 天耀二期 8 * 楊勃隆 9 */ 10 public class HomeWork06 { 11 public static void main(String[] args){ 12 int num,sd,td,hd; 13 for(num=100;num<1000;num++) 14 { 15 hd=num/100; 16 td=(num-100*hd)/10; 17 sd=num%10; 18 if(num==hd*hd*hd+td*td*td+sd*sd*sd) 19 { 20 System.out.print("水仙花數字:"+num+"\n"); 21 } 22 } 23 } 24 }

其實都差不多哈,前面已經有了C寫的水仙花數字!