酷代码 AI
菜单
服务商

Java 实现:求解 100 到指定整数区间内的水仙花数数量

以下是使用 Java 解决此问题的代码: ```java import java.util.Scanner; public class NarcissisticNumber { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int count = 0; for (int i = 100; i <= n && i <= 999; i++) { int hundreds = i / 100; int tens = (i % 100) / 10; int units = i % 10; if (hundreds * hundreds * hundreds + tens * tens * tens + units * units * units == i) { count++; } } if (count == 0) { System.out.println("not found"); } else { System.out.println(count); } } } ``` ######[AI写代码神器 | 209点数解答 | 2024-10-18 18:05:55]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]