题解 | #水仙花数#

水仙花数

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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext())
        {
            int flag=0;
            int m=sc.nextInt();
            int n=sc.nextInt();
            for(int i=m;i<=n;i++)
            {
                int one=i/100;
                int two=i%100/10;
                int three=i%10;
                if(i==(Math.pow(one,3)+Math.pow(two,3)+Math.pow(three,3)))
                {
                     System.out.print(i+" ");
                     flag=1;
                }
            }
            if(flag==0)
            {
                System.out.println("no");
            }
         }
    }
}

全部评论

相关推荐

asdasdasda...:19岁,不容易啊可能升个本会好点,现在学历歧视太严重了
点赞 评论 收藏
分享
06-18 13:28
已编辑
门头沟学院 Web前端
爱睡觉的冰箱哥:《给予你300的工资》,阴的没边了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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