编程中还存在着四叶草数的说法,它个位的四次方、十位的四次方、百位的四次方和千位的四次方的和等于其本身。编写程序判断一个数是否为四叶草数,如果是则输出YES,否则输出NO。
你可以参考一下,希望采纳
import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int a = num % 10; // 个位
int b = num / 10 % 10; // 十位
int c = num / 100 % 10; // 百位
int d = num / 1000 % 10; // 千位
if ((a * a * a * a + b * b * b * b + c * c * c * c + d * d * d * d) == num) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}