打印出100到999的水仙花数


所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个水仙花数,因为153=1*1*1 + 5*5*5 + 3*3*3

 

 1 public class Flower
 2 {
 3     public static void main(String[] args)
 4     {
 5         int temp=0;
 6         System.out.println("水仙花数为:");
 7         for (int i=100;i<999 ;i++ )
 8         {
 9             temp = i;
10             int x= temp/100;//算出百位数,  因为x是int类型 所以小数省去
11             int y= temp%100/10;//算出十位数
12             int z= temp%10;//算出个位数
13             if (i==x*x*x+y*y*y+z*z*z)
14             {
15                 System.out.println(i);
16             }
17         }
18     }
19 }

 运行结果为:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM