PS: This question is out of 100, did not do, everybody helps to see where the problem is
/*
* Title: Narcissus number upgrade version
* Description: Narcissus number refers to an n-digit number (n≥3), and its number on each bit of the sum of n is equal to its own. (Example: 1^3 + 5^3+ 3^3 = 153)
Give you A and B, how many daffodils are there in the [a b] interval
Topic Category: Loops, lookups, enumerations, bitwise operations
Difficulty: Intermediate
Score: 100
Run time limit: Unlimited
Memory Limit: Unlimited
Stage: Application for examination
Input: Two positive integers, separated by a space, to ensure that the number is less than or equal to 1000000.
Output: A number representing the number of daffodils in the [a, b] interval
Sample input: 100 1000
Sample output: 4
Answer hint: The number of daffodils in 100~1000:153,370,371,407
*/
1 ImportJava.util.Scanner;2 3 Public classMain {4 5 Public Static voidMain (string[] args) {6 7 intA = 0;8 intb = 0;9 intCount = 0;Ten OneScanner s =NewScanner (system.in); AString str =s.nextline (); -string[] Strarray = Str.split (""); -A = Integer.parseint (strarray[0]); theb = Integer.parseint (strarray[1]); - s.close (); - if(A < | | a > 1000000) | | (B < | | b > 1000000)) - { + Throw Newruntimeexception (); - } + ACount =Getnum (A, b); at - System.out.println (count); - } - - Public Static intGetnum (intAintb) { - in intresult = 0; - to for(inti = A; I <= b; i++) + { - intm =i; the intTMP = 0; * intValue = 0; $ Panax Notoginseng while(0! =m) - { the +TMP = M%10; AValue + = Math.pow (tmp, 3); theM/= 10; + } - $ if(Value = =i) $ { -result++; - } the } - returnresult;Wuyi } the -}
Huawei on-machine test question (Narcissus number upgrade version-java)