The so-called "Narcissus number" refers to a three-digit number, whose numbers are cubic and equal to the number itself.
The Java program code is as follows:
Public classArithtest { Public Static voidMain (string[] args) {arithtest at=Newarithtest (); //Print all the daffodils numberSystem.out.println ("Narcissus number:"); for(inta=100;a<=999;a++){ BooleanBL =AT.FK (a); if(BL) {System.out.println (a); } } /*Number of Daffodils * the so-called "Narcissus number" refers to a three-digit number, whose numbers are cubic and equal to the number itself. * Print all daffodil numbers*/ Public Booleanfkinta) { intx = a/100; inty = A%100/10; intz = a%100%10; intK = x*x*x+y*y*y+z*z*Z; if(A = =k) { return true; } Else { return false; } }}
The results of the implementation are as follows:
number of daffodils:153370371407
Algorithm Exercise 3---Daffodil number Java edition