题解 | #水仙花数#

水仙花数

https://www.nowcoder.com/practice/dc943274e8254a9eb074298fb2084703

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextInt()) {
            int m = scan.nextInt();
            int n = scan.nextInt();
            int x = 0;
            for (int i = m; 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.print(i + " ");
                    x = 1;
                } else {
                    if (i == n && x == 0) {
                        System.out.println("no");
                    }
                }
            }
        }
    }
}

全部评论

相关推荐

鼠鼠求offer鸭:没事,骗一次就老实不会幻想有好事砸中自己了😂😂
点赞 评论 收藏
分享
投递汇川技术等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务