题解 | 水仙花数
水仙花数
https://www.nowcoder.com/practice/dc943274e8254a9eb074298fb2084703
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()){
int m = sc.nextInt();
int n = sc.nextInt();
judge(m,n);
}
sc.close();
}
public static int judge(int m,int n) {
int count=0;
for (int i = m; i <= n; i++) {
if (judge1(i)) {
System.out.print(i+" ");
count++;
}
}
if(count==0){
System.out.println("no");
}
return 0;
}
public static boolean judge1 ( int num){
int temp = 0;
int sum = 0;
int n = num;
while (n != 0) {
temp = n % 10;
n /= 10;
sum += temp * temp * temp;
}
if (sum == num) {
return true;
}
return false;
}
}

