Download API_project/Math_module/src/Math_Case/Narcissistic_number.java from zxy0307/Java: direct link, hf CLI and curl.
- Browser
- Download file 762 Bytes
-
https://huggingface.co/zxy0307/Java/resolve/main/API_project/Math_module/src/Math_Case/Narcissistic_number.java
- Command line
-
hf download hf://zxy0307/Java/API_project/Math_module/src/Math_Case/Narcissistic_number.java
-
curl -L -o Narcissistic_number.java https://huggingface.co/zxy0307/Java/resolve/main/API_project/Math_module/src/Math_Case/Narcissistic_number.java
762 Bytes
| package Math_Case; | |
| public class Narcissistic_number { | |
| public static void main(String[] args) { | |
| //要求1:统计一共有多少个水仙花数 | |
| //水仙花数:100~999 | |
| int count = 0; | |
| //得到每一个三位数 | |
| for (int i = 100; i <= 999; i++) { | |
| //个位 十位 百位 | |
| int ge = i % 10; | |
| int shi = i / 10 % 10; | |
| int bai = i / 100 % 10; | |
| //判断: | |
| //每一位的三次方之后 跟本身 进行比较 | |
| double sum = Math.pow(ge, 3) + Math.pow(shi, 3) + Math.pow(bai, 3); | |
| if (sum == i) { | |
| count++; | |
| System.out.println(i); | |
| } | |
| } | |
| System.out.println(count); | |
| } | |
| } | |