【Program3]
Question: print out all the "Daffodils". The so-called "Daffodils" refers to a three-digit number.CubeAnd equals to the number itself. For example, 153 is a "Daffodils" because 153 = the power of 1 + the power of 5 + the power of 3.
Program Analysis: first, the three-digit number 100-999. Second, you must calculate the number of each digit and the number equal to this number. The public int Ge (int n) can be obtained ); // obtain the number of public int Shi (int n); // obtain ten public int Bai (int n); // obtain a hundred digits.
Package endual; public class qanswer {public int shuixianhua (int n) {int Ge = This. ge (n); int Shi = This. shi (n); int Bai = This. bai (n); int res = Ge * Ge + Shi * Shi + Bai * Bai; If (n = res) {return N ;} return 0;} private int Ge (int n) {return n % 10;} private int Shi (int n) {return (N % 100)/10; // The number must be rounded up.} private int Bai (int n) {return N/100; // directly integer }}
package endual; public class main ,.... How many public static void main (string [] ARGs) {// todo auto-generated method stub // int n = 8; qanswer Qu = new qanswer (); For (INT n = 100; n <= 999; n ++) {int res = Qu. shuixianhua (n); If (0! = Res) {system. Out. println (RES) ;}}}