如何用Java输出所有四叶玫瑰数

2024-10-11 21:16:18

四位数各位上的数字的四次方之和等于本身为四叶玫瑰数。是指一个 四位数 ( n=4),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^4 + 6^4+ 3^4 + 4^4= 1634)

如何用Java输出所有四叶玫瑰数

2、创建工程,或使用已有工程,在工程下创建包,包内新建一个类,我命名为FourLeafRoses类,大家根据自己喜好随便命名,但请保持类名与文件名一致。

如何用Java输出所有四叶玫瑰数

4、判断这个数是不是水仙花数,求每一位数上的数的四次方和是否为原数字本身。private static Boolean isFourLeafRoses(int number) {  int thousands = number / 1000;  int hundreds = number / 100 - thousands * 10;  int tens = number / 10 - hundreds * 10 - thousands * 100;  int ones = number % 10;  return fours(thousands) + fours(hundreds)        + fours(tens) + fours(ones) == number;}

如何用Java输出所有四叶玫瑰数
猜你喜欢