水仙花數

水仙花數

水仙花數是指一個 3 位數,它的每個位上的數字的 3次冪之和等於它本身(例如:1^3 + 5^3+ 3^3 = 153)。

public class waterFlowerNum {

	public static void waterFlower() {
		//	求出個、十、百的數字
		for(int i=100;i<1000;i++) {
			int g = i/1%10;
			int s = i/10%10;
			int b = i/100;
			if(g*g*g + s*s*s + b*b*b==i) {
				System.out.print(i + " ");
			}
		}
	}
	
	public static void main(String[] args) {
		
		waterFlower();
		
	}
	
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章