开发者社区 问答 正文

求解水仙花数

screenshot
这题算了一半只能自动检索却不能自己手动输入判断!求大神讲解啊!

展开
收起
蛮大人123 2016-06-06 11:35:33 1984 分享 版权
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
    public class Sxh {
    
    public static void main(String[] args) {
        while (true) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int i = Integer.parseInt(s);
        int a = i / 100;//百位
        int b = (i - a * 100) / 10;//十位
        int c = (i - a * 100 - b * 10);//个位
    
        if (a * a * a + b * b * b + c * c * c == i) {
            System.out.println(i+"是水仙花数");
        }else{
            System.out.println(i+"不是水仙花数");
        }
        }
    
    }
    }
    2019-07-17 19:28:03
    赞同 展开评论
问答地址: