/**功能:打印水仙花数...
* 作者:许锐
* 日期:2022年4月07日
*/
public class Task05 {
public static void main(String[] args) {
int p3, p2, p1 , count;
count = 0;
for (int n = 100; n<=999; n++) {
m = n;
p1 = m % 10; //个位数
n = m / 10;
p2 = m % 10; //十位数
p3 = m / 10; //百位数
if (n == p3 * p3 * p3 + p2 * p2 * p2 + p1 * p1 * p1) {
count++;
System.out.println(n + "=" + p3 + "^3+" + p2 + "^3 +" + p1 + "^3");
}
}
System.out.println("总共有" + count + "个水仙花数。");
}
}
01-05
263
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-06
7502
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-15
773
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-13
686
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)