Java algorithm question 3. Print out all the daffodils.

Source: Internet
Author: User

[Original reprint annotated Source]

Title 3: Print out 100-999 of all narcissus numbers.

Ideas:

Narcissus number refers to an n-digit number (n≥3), and the sum of the number of its digits on each bit is equal to its own.

(Example: 1^3 + 5^3+ 3^3 = 153)

Java Code Implementation

1  PackageJichu;2 3  Public classJICHU34 {5      Public Static voidMain (string[] args)6     {7         intB, S, G;8          for(inti = 100; i < 1000; i++)  9         {Teng = i% 10;//g storage single digit Ones = (I/10)% 10;//s Save 10 digits Ab = i/100;//b Storage of hundred -              -             //if it's a 1000-digit number, the sum of 3 powers equals it itself . the             if(i = = ((g*g*g) + (s*s*s) + (b*b*b ))) -             { -SYSTEM.OUT.PRINTLN (i + "narcissus number")); -             }  +         } -     } +}

[Original reprint annotated Source]

Java algorithm question 3. Print out all the daffodils.

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.