水仙花数------"水仙花数 "是指一个三位数,其各位数字立方和等于该数本身。(for循环的嵌套)

package com.zuoye.test;
//打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数,
//其各位数字立方和等于该数本身。
//例如:153是一个 "水仙花数 ",
//因为153=1的三次方+5的三次方+3的三次方。
public class Shuixian {
public static void main(String[] args)
{
int a;
int b;
int c;
int sum1=0;
int sum2=0;
for(a=1;a<10;a++)
{
for(b=0;b<10;b++)
{
for(c=0;c<10;c++)
{
sum1=100*a+10*b+c;
sum2=a*a*a+b*b*b+c*c*c;
if(sum1==sum2)
{
System.out.println(sum1);
}
}
}
}
}
}

 

posted @ 2016-09-12 22:29  丶疏影横斜  阅读(1908)  评论(0编辑  收藏  举报