Java interview one question per day 8

Source: Internet
Author: User

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.
1. Program Analysis: Use for loop control 100-999 number, each number decomposition out of bits, 10 bits, hundred.

ImportJava.util.Scanner; Public classShuixianhua { Public  Static voidMain (string[] args) {//System.out.println ("Please enter a three-digit number:");//Scanner sc=new Scanner (system.in);//int num=sc.nextint ();         for(inti=100;i<=999;i++){            Booleanflag=false; inta=i/100; intB=i%100/10; intC=i%100%10; DoubleResult=math.pow (A, 3) +math.pow (b, 3) +math.pow (c, 3); if(i==result) {Flag=true; }Else{flag=false; }            if(flag==true) {System.out.println (i+ "The number of daffodils"); }        }                    }}

Java interview one question per day 8

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.