题目:
* 输入正整数N,检查它是否完美输出YES或者NO。
* 把一个数字的每一位拆分开,计算他们的阶乘再累加,如果和等于原数字,则该数字是完美的。
* eg:
* 145
* 1 + 4*3*2*1 + 5*4*3*2*1 == 145
---------------------------------------------
阶层的意思:5! = 5的阶层 = 5*4*3*2*1
做法:
class Test61 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int number = scanner.nextInt();
scanner.close();
if (isPerfectNumber(number)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
public static boolean isPerfectNumber(int number) {
int total = 0;
String s = String.valueOf(number);
for (int i = 0; i < s.length(); i++) {
Integer n = Integer.valueOf(String.valueOf(s.charAt(i)));
int r = jieCen(n);
total += r;
}
if (total == number){
return true;
}else {
return false;
}
}
//一个数的阶层
public static int jieCen(int number) {
int sum = 1;
for (int i = 1; i <= number; i++) {
sum *= i;
}
return sum;
}
}
标签:String,完美,System,number,int,static,total,数字
From: https://www.cnblogs.com/chen-zhou1027/p/17467771.html