Ideas: the first to use a for loop through all the numbers between 100-999, then if satisfied bits plus cubic cubic cubic plus one hundred ten is equal to the original number, then the number is "the number of Narcissus", statistics variables ++;
Code:
public class Demo1 {
public static void main(String[] args) {
int count = 0;
for(int i =100;i<1000;i++) {
int a = i%10;
int b = i/10%10;
int c= i/10/10%10;
if((a*a*a+b*b*b+c*c*c) == i ) {
count++;
}
}
System.out.println("水仙花数的个数为:"+count);
}
}
effect: