Java Exercise (iii)--Number of daffodils

Source: Internet
Author: User
Tags pow

Title: Print out all the "daffodils", the so-called "Narcissus number" refers to a three-digit number, its number of cubes and equal to the number itself. For example: 153 is a "narcissus number", because the 153=1 three times the square +5 of the three +3 Times Square.

Program Analysis: Use for loop control 100-999 number, each number decomposition out of bits, 10 bits, hundred.

 Public classTest1 { Public BooleanIsshui (intN) {intx=n/100;//Hundred        inty= (n-x*100)/10;//10 Guests        intz=n-x*100-y*10;//Digit        if(N==math.pow (x, 3) +math.pow (Y, 3) +math.pow (Z, 3))            return true; Else            return false; }     Public Static voidMain (String args[]) {Test1 test=NewTest1 ();  for(inti=100;i<1000;i++) {            if(Test.isshui (i)) System.out.println (i); }    }}

Java Exercise (iii)--Number of 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.