ps:水仙花数(Narcissistic number)也被称为超完全数字不变数(pluperfect digital invariant, PPDI)、自恋数、自幂数、阿姆斯壮数或阿姆斯特朗数(Armstrong number),水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身(例如:)
java 实现:
public void main(String[] args) {
int num, sd, td, hd;
for (num = 100; num < 1000; num++) {
hd = num / 100;
td = (num - 100 * hd) / 10;
sd = num % 10;
if (num == hd * hd * hd + td * td * td + sd * sd * sd) {
System.out.print("水仙花数字:" + num + "\n");
}
}
}