6.编写一个Java应用程序,该应用程序包括2个类:Print类和主类E。Print 类里有一个方法output()功能是输出100 ~ 999之间的所有水仙花数(各位数字的 立方和等于这个三位数本身,如: 371 = 33 + 73 + 13。)在主类E的main方法中来 测试类Print。

Print类:
package com.bao;

public class Print {
int g,s,b;
void outPut()
{
for(int i=100;i<1000;i++)
{g=i%10;
s=i/10%10;
b=i/100;
if(ggg+sss+bbb==i)
{System.out.println(i);}
}
}

}
主类E:
package com.bao;

public class E {

public static void main(String[] args) {
	Print shui=new Print();
	shui.outPut();	
	System.out.println();

}

}

posted @ 2016-09-17 10:22  削肾客  阅读(2219)  评论(0编辑  收藏  举报