Exercise: Find out all the daffodils in.
Analysis: the number of daffodils refers to a three-digit number.CubeAnd equals to the number itself. For example: 370 = 33 + 73 + 00. This indicates that 370 is a daffodils.
Therefore, to determine whether a three-digit number is a daffodils number, you must first obtain the three-digit number, ten digits and hundreds of digits. Here I will use the following methods:
1:
First, get his hundred bits: int Wei = x/100; Because int is an integer, it will not be rounded down or the number after the decimal point.
Ten more digits: int Shiwei = (X-Wei * 100)/10. Use this number to subtract the hundred digits * 100, and then divide it by 10 for the same reason.
Finally, obtain the single digit: int gewei = x-yaowei * 100-shiwei * 10. Obviously, you can obtain the single digit.
2:
Intb = x/0/100;
Int S = x/100% 10;
Int G = x % 10;
Method of cube calculation:
1, x = Wei * Wei + Shiwei * Shiwei + gewei * gewei2. The method for raising the power of supply and demand in Java is Java. lang. math. pow (a, B); it indicates the power B of.
LastProgram:
First:
Public Class Shuixianhuashu { Public Static Void Main (string [] ARGs ){ Int X = 0; // Define the number of daffodils For ( Int I = 100; I <= 999; I ++ ){ Int B = I/100; // Hundreds of BITs Int S = (i-100 * B)/10; // Dozens Int G = (I-s * 10-B * 100 ); // Obtain a single digit If (I = g * g + S * s + B * B * B) {x ++; // X + 1 if the number of daffodils is met each time; System. Out. Print (I + ""); // Number of output conforming Conditions } System. Out. println (); // Line feed System. Out. println ("daffodils total" + x + "); // Total number of output daffodils }}
Second:
Public Class Shuixianhuashu { Public Static Void Main (string [] ARGs ){ Int X = 0; // Define the number of daffodils For ( Int I = 100; I <= 999; I ++ ){ Int B = I/100; // Hundreds of BITs Int S = I % 100/10; // Dozens Int G = I % 10; // Obtain a single digit If (I = math. Pow (B, 3) + math. Pow (s, 3) + math. Pow (G, 3)) {X ++; // X + 1 if the number of daffodils is met each time; System. Out. Print (I + ""); // Number of output conforming Conditions } System. Out. println (); // Line feed System. Out. println ("daffodils total" + x + "); // Total number of output daffodils }}