Digital Black Hole-6174

Source: Internet
Author: User

1  PackageCom.niit.niitdigitalblackhole6174.main;2 3 /**4 * Verify Math black hole The user enters a four-digit number, and the input transforms to 61745 * For example: 12346 * 4321-1234 = 30877 * 8730-0378 = 83528 * 8532-2358 = 61749  * @authorFatolandTen  */ One  Public classDigitalBlackHole6174 { A  -      -      Public Static intGetResult (intNumber ) { the         intresult = Getsortednumber (number)-Getreversednumber (Getsortednumber (number)); -         returnresult; -     } -      +      Public Static intGetsortednumber (intNumber ) { -         intDigitstester =getdigitstester (number); +          A         //calculates that 1000 is 10 of the 3-time Square at         intexponent = (int) math.log10 (digitstester); -          -         int[] Temparray =New int[4]; -          for(inti = 0; I <= exponent; i++) { -             //Temparray[i] = 1234/1000 = 1 -Temparray[i] = number/Digitstester; in             //Number = 1234-1234/1000 (=1) * = 234 -Number = Number-number/digitstester *Digitstester; to             //Digitstester = 1000/10 = +Digitstester = DIGITSTESTER/10; -         } the          *         int[] Sortedarray =Getsortedarray (temparray); $         intTemp1 = sortedarray[3];Panax Notoginseng         intTemp2 = sortedarray[2]; -         intTemp3 = sortedarray[1]; the         intTemp4 = sortedarray[0]; +          A //int sortednumber = 0; the         intDigitsTester2 =getdigitstester (number); + //for (int i = sortedarray.length-1; i > 0; i--) { - //sortednumber = sortedarray[i] * DIGITSTESTER2; $ //DigitsTester2/=; $ //        } -         intSortednumber = Temp1 * + temp2 * + Temp3 * + temp4 * 1; -         returnSortednumber; the     } -     Wuyi      Public Static int[] Getsortedarray (int[] temparrayforsort) { the          for(inti = 0; i < temparrayforsort.length-1; i++) { -             intCurrentmin =Temparrayforsort[i]; Wu             intCurrentminindex =i; -              About              for(intj = i + 1; J < Temparrayforsort.length; J + +) { $                 if(Currentmin >Temparrayforsort[j]) { -Currentmin =Temparrayforsort[j]; -Currentminindex =J; -                 } A             } +              the             if(Currentminindex! =i) { -Temparrayforsort[currentminindex] =Temparrayforsort[i]; $Temparrayforsort[i] =currentmin; the             } the         } the         returnTemparrayforsort; the     } -  in      Public Static intGetreversednumber (intSortednumber) { the         intReversednumber = 0; the         intTempforreverse = 0; About         intDigitstester =Getdigitstester (sortednumber); the  the         //calculates that 1000 is 10 of the 3-time Square the         intexponent = (int) math.log10 (digitstester); +          for(inti = 0; I <= exponent; i++) { -             //Temp1 = 1234/1000 = 1 theTempforreverse = Sortednumber/Digitstester;Bayi             //Number = 1234-1234/1000 (=1) * = 234 theSortednumber = Sortednumber-sortednumber/digitstester *Digitstester; the             //Digitstester = 1000/10 = -Digitstester = DIGITSTESTER/10; -             //reversednumber = 0 + 1 * 10^0 theReversednumber = Reversednumber + Tempforreverse * (int) Math.pow (10, i); the //if (reverseTemp1 = = 0) { the //Reversednumber = reversednumber + (int) Math.pow (ten, i); the //            } -         } the         returnReversednumber; the     } the     94      Public Static intGetdigitstester (intSortednumber) { the         intDigitstester = 0; the         //calculates that number is a positive integer of several the         //e.g. i = ten; i < 1234; I *=98          for(inti = 10; i < Sortednumber; I *= 10) { About             //Digitstester = + -Digitstester =i;101             //If i = 10000 > 1234, digitstester = 1000/10 =102             if(I >Sortednumber) {103Digitstester/= 10;104 //Break ; the             }106         }107         returnDigitstester;108     }109}

Digital Black Hole-6174

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.