算法训练 水仙花

                                              算法训练 水仙花

 水仙花数
问题描述
  判断给定的 三位数是否 水仙花 数。所谓 水仙花 数是指其值等于它本身 每位数字立方和的数。例 153 就是一个 水仙花 数。 153=1 3+5 3+3 3
输入格式
  一个整数。
输出格式
  是水仙花数,输出"YES",否则输出"NO"(不包括引号)
样例输入
123
样例输出
NO
数据规模和约定
  一个三位的整数,否则输出"NO"
import java.util.*;
public class Main {
	public static void fun(int n)
	{   
		  int a=n%10;       
		  int b=n/10%10;   
		  int c=n/100%10;  
 	     	if(n==(a*a*a+b*b*b+c*c*c))
 	     		System.out.print("YES");
 	     	else
 	     		System.out.print("NO");
		  

	}
	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		  int n=in.nextInt();
		  fun(n);
	}

}


猜你喜欢

转载自blog.csdn.net/sinat_27406925/article/details/51132221