使用java代码输出所欲水仙花数
时间: 2023-10-24 10:17:03 浏览: 35
Sure, I’d be happy to help you with that! Here’s an example Java code to output all the Narcissistic numbers:
```java
public class NarcissisticNumber {
public static void main(String[] args) {
int n = 100;
int i = 0;
while (n <= 999) {
int a = n / 100;
int b = n / 10 % 10;
int c = n % 10;
if (n == a * a * a + b * b * b + c * c * c) {
i++;
System.out.print(n + " ");
}
n++;
}
System.out.println("\nThere are " + i + " Narcissistic numbers from 100 to 999.");
}
}
```
This code outputs all the Narcissistic numbers from 100 to 999, and counts the total number of Narcissistic numbers. I hope this helps!
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)