牛客网真题-68-水仙花数

水仙花数

http://www.nowcoder.com/questionTerminal/11c9f023a9f84418a15b48792a5f7c70

//先算一下1000以内的水仙花数

import java.util.ArrayList;
import java.util.Scanner;
public class Main {
    public static boolean just(Integer in){
        int temp = in, cnt = 0;
        while (temp > 0) {
            int m = temp % 10;
            temp = temp / 10;
            cnt += m * m * m;
        }
        if(cnt == in){
            return true;
        }else{
            return false;
        }
    }

    public static void main(String[] args){
        int[] ints = new int[]{153, 370, 371, 407};
        //        for(int i = 100; i < 1000; i++){
        //            if(just(i)){
        //                System.out.println(i);
        //            }
        //        }

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt(), m = scanner.nextInt();
            ArrayList<Integer> arrayList = new ArrayList<>();
            for(int i = 0; i < ints.length; i++){
                if(ints[i] >= n && ints[i] <= m){
                    arrayList.add(ints[i]);
                }
            }
            if(arrayList.size() == 0){
                System.out.println("no");
            }else{
                for(int i = 0; i < arrayList.size() - 1; i++){
                    System.out.print(arrayList.get(i) + " ");
                }
                System.out.println(arrayList.get(arrayList.size() - 1));
            }

        }
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
06-12 18:53
第一次听说还有无水工作!!!又是被刷新三观的一天
Lynn012:666第一次听到,你给他说这里不方便我们加个微信
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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