The number of daffodils in Java program printing 100~999

Source: Internet
Author: User

  

 PackagePrintdaffodilnumber;/** Title: Print out all of the "daffodils", the so-called "Narcissus number" refers to a three-digit number, its number of cubes and equal to the number itself. (100~1000) * For example: 153 is a "narcissus number", because 153=1 three times +5 of the three +3 Times Square. */ Public classPrintnumber {Static intNumber1; Static intnumber2; Static intNumber3; //corresponds to Bits, 10 bits, hundred         Public Static voidMain (string[] args) {//TODO auto-generated Method StubFun (); }        Private Static voidFun () { for(inti = 100;i<1000;i++) {Number1= i%10; Number2= i/10%10; Number3= i/100; if(Number1*number1*number1+number2*number2*number2+number3*number3*number3 = =i)            {System.out.println (i); }        }    }}

The output is:

153
370
371
407

The number of daffodils in Java program printing 100~999

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.