打印出所有的 "水仙花数 "

题目:打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数, 其各位数字立方和等于该数本身。 例如:153是一个 "水仙花数 ",因为153=1的三次方+5的三次方+3的三次方。

public class exp3 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		for(int i=100;i<1000;i++) {
			if(shuixianhua(i)) {
				System.out.println(i);
			}
				
		}

	}
	public static boolean shuixianhua(int x) {
		int i=0,j=0,k=0;
		i=x/100;
		j=(x%100)/10;
		k=x%10;
		if(x==i*i*i+j*j*j+k*k*k)
			return true;
		else
			return false;
		
	}

}
发布了3 篇原创文章 · 获赞 0 · 访问量 2

猜你喜欢

转载自blog.csdn.net/qq_38776359/article/details/105492370
今日推荐