水仙花数

水仙花数

时间限制: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;
	}
	
}

  

posted on 2016-05-12 13:46  airycode  阅读(219)  评论(0编辑  收藏  举报

导航