public class Demo
{
public static void main(String[] args){
for(int i=100; i<1000; i++)
{
if(flower(i))
{
System.out.println(i);
}
}
}
//创建一个方法用与判断是否为水仙花数
public static boolean flower(int num)
{
int bai = num / 10 / 10;
int shi = num /10 % 10;
int ge = num % 10;
if(num == (bai*bai*bai + shi*shi*shi + ge*ge*ge))
{
return true;
}
return false;
}
} |