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