天天看点

Java实现水仙花数【三位数】

package mathTest;
/**
 * 三位数水仙花数的实现
 * @author Youjc
 *
 */
public class ShuiXianHuaShu {

	public ShuiXianHuaShu() {
		// TODO Auto-generated constructor stub
		//最大幂次数
		for(int k=0;k<4;k++)
		{
			//百
			for(int c=1;c<10;c++)
			{
				//十
				for(int t=0;t<10;t++)
				{
					//个
					for(int z=0;z<10;z++)
					{
						if(Math.pow(z, k)+Math.pow(t, k)+Math.pow(c, k)==(c*100+t*10+z))
						{
							System.out.println("幂次数:="+k+",三位数值:"+(c*100+t*10+z));
						}
					}
				}
			}
		}
	
	}
	
	public static void main(String[] args) {
		new ShuiXianHuaShu();
	}

}