/** * 求水仙花数 * @param left * @param right */ static void checkFlowerNumber(int left,int right){ for (int i = left; i <= right; i++) { char[] ch = (i+"").toCharArray(); int sum = 0; int num = 0; for (int j = 0; j < ch.length; j++) { num = Integer.parseInt(ch[j]+""); sum += num*num*num; } if (sum == i) { System.out.println(i); } } }
时间: 2024-09-28 21:02:42