如何用Java判断水仙花数

2024-10-17 00:06:00

水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3+ 3^3 = 153)

如何用Java判断水仙花数

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

如何用Java判断水仙花数

4、判断这个数是不是水仙花数,求每一位数上的数的立方和是否为原数字本身。private static Boolean isNarcissistic(int number) {  int hundr髫潋啜缅eds = number / 100;  int tens = number / 10 - hundreds * 10;  int ones = number % 10;  return cube(hundreds) + cube(tens) + cube(ones) == number;}

如何用Java判断水仙花数
猜你喜欢