zoukankan      html  css  js  c++  java
  • 水仙花数

    水仙花数

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:0
     
    描述
    请判断一个数是不是水仙花数。
    其中水仙花数定义各个位数立方和等于它本身的三位数。
     
    输入
    有多组测试数据,每组测试数据以包含一个整数n(100<=n<1000)
    输入0表示程序输入结束。
    输出
    如果n是水仙花数就输出Yes
    否则输出No
    样例输入
    153
    154
    0
    样例输出
    Yes
    No

    import java.util.Scanner;
    
    
    public class Main13 {
    
    	public static void main(String[] args) {
    		Scanner input = new Scanner(System.in);
    		while (input.hasNext()) {
    			int num = input.nextInt();
    			if (num == 0) {
    				break;
    			}
    			
    			String result = solove(num);
    			System.out.println(result);
    			
    		}
    		input.close();
    	}
    
    	private static String solove(int num) {
    		String result = "";
    		int ge = num%10;
    		int qian = num/100;
    		int bai = num/10%10;
    		
    		if (Math.pow(ge, 3) +Math.pow(qian, 3) + Math.pow(bai, 3) == num) {
    			result = "Yes";
    		}else{
    			result = "No";
    		}
    		
    		
    		return result;
    	}
    	
    }
    

      

  • 相关阅读:
    matplotlib绘制常见统计图
    学习进度(14)
    hive的基本用法(2)
    hive的基本用法(1)
    进度日报表10
    进度日报表09
    进度日报表08
    进度日报表07
    第六周总结
    进度日报表06
  • 原文地址:https://www.cnblogs.com/airycode/p/5485386.html
Copyright © 2011-2022 走看看