Daffodil number definition:
The so-called "narcissus number" refers to a three-digit number, the sum of the cubes of each digit is equal to the number itself. Example: 153 is
A "daffodil number", because 153 = 1 to the 3rd + 5 to the 3rd + 3 to the 3rd.
Task: Print out all "Daffodil Numbers",
code:
public class Flow {
public static void main(String[] args) {
for (int i = 100; i < 1000; i++) {
// int i = 201;
int a = i / 100;
int b = (i % 100) / 10;
int c = ((i % 100) % 10);
if (i == a * a * a + b * b * b + c * c * c) {
System.out.println("flower is : " + i);
// }else{
// System.out.println("wrong");
// }
}
}
}
}
result: