java 输出小于n的所有水仙花数
时间: 2023-04-02 20:05:13 浏览: 155
java java
以下是 Java 代码,可以输出小于 n 的所有水仙花数:
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 100; i < n; i++) {
int a = i / 100;
int b = i / 10 % 10;
int c = i % 10;
if (a * a * a + b * b * b + c * c * c == i) {
System.out.println(i);
}
}
}
}
```
阅读全文