题解 | #水仙花数#

水仙花数

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

import java.util.Scanner;
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");
                    }
                }
            }
        }
    }
}
Java基础练习题 文章被收录于专栏

都是一些基础的语法题目,每天可以刷几道。

全部评论

相关推荐

点赞 评论 收藏
分享
评论
5
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务