To find out all the "daffodils", the so-called "Narcissus number" refers to a three-digit number, whose numbers are cubic and equal to the number itself.
1 /**2 * Title: Print out all of the "daffodils", the so-called "Narcissus number" refers to a three-digit number, its number of cubes and equal to the number itself. 3 * For example: 153 is a "narcissus number", because the 153=1 three times the square +5 of three +3 Times Square. 4 * 1. Program Analysis: Use for loop control 100-999 number, each number decomposition out of bits, 10 bits, hundred. 5 * 6 */7 Public classDaffodilsdata {8 Public Static voidMain (string[] args) {9 intA, B, C, D;Ten intdata; OneSystem.out.println ("The number of daffodils is:"); A for(inti = 100; I < 999; i++) { -A = i/100; -b = (i-100 * a)/10; thec = i-100 * a-10 *b; -data = A * A * a + b * b * b + c * c *C; - if(Data = =i) { - System.out.println (i); + } - } + } A}
Number of daffodils