什么是水仙花數
水仙花數(Narcissistic number)也被稱為超完全數字不變數(pluperfect digital invariant, PPDI)、自戀數、自冪數、阿姆斯壯數或阿姆斯特朗數(Armstrong number),水仙花數是指一個 3 位數,它的每個位上的數字的 3次冪之和等于它本身(例如:1^3 + 5^3+ 3^3 = 153)。
實現方法
public class shuixianhuashu {
public static void main(String[] args) {
// TODO 自動生成的方法存根
for (int i = 100; i < 1000; i++) {
int a = i / 100;//得到百位數
int b = i / 10 % 10;//得到十位數
int c = i % 10;//得到個位數
//求和雨原來得數比較結果是否相等
if (Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3) == i) {
System.out.println("該數字是水仙花數:" + i);
}
}
}
}