编写一个Java应用程序,该应用程序包括2个类:ShuiXianHuaShu类和主类E。Print类里有一个方法output()功能是输出100 ~ 999之间的所有水仙花数(各位数字的立方和等于这个三位数本身,如: 371 = 33 + 73 + 13。)在主类E的main方法中来测试ShuiXianHuaShu类。
void outPut() {
for (int i = 100; i < 999; i++)
{
int bai = i / 100;
int shi = (i % 100) / 10;
int ge = (i % 100) % 10;
if (bai * bai * bai + shi * shi * shi + ge * ge * ge == i)
{
System.out.println(i);
}
}
}
public static void main(String[] args)
{
ShuiXianHuaShu Shu=new ShuiXianHuaShu();
Shu.outPut();
}
运行结果