java 水仙花数 提升档次解法

输出所有的水仙花数,把谓水仙花数是指一个数3位数,其各各位数字立方和等于其本身,
例如: 153 = 1*1*1 + 3*3*3 + 5*5*5

// 六行代码解决 

public static void main(String[] args) throws ParseException {

for(int a = 100;a<1000;a++) {
int i = (int) Math.ceil(a/100);
int j = (int) Math.ceil(((int) a%100)/10);
int k = a%100%10;
if (a == Math.pow(i, 3) + Math.pow(j, 3) + Math.pow(k, 3)) {
System.out.println(a);
}
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章