怎么做0-1000之间的水仙花数~~
急求助 考试要用  要正确 最好标上中文注释 求你们了 我门要互相帮助~~

解决方案 »

  1.   

    public class Test
    {
        private boolean method(int i)
        {
            int one;
            int two;
            int three;
            boolean b=true;
            if(i>1000)
                b=false;
            else
            {
                one=i%10;
                two=(i%100-one)/10;
                three=(i-one-two*10)/100;
                if((one*one*one+two*two*two+three*three*three)!=i)
                    b=false;
            }
            return b;
                
        }
            
        public static void main(String[] args)
        {
            Test t=new Test();
            for(int i=0;i<1000;i++)
            {
              if(t.method(i))
                System.out.println(i);
            }
        }
    }
      

  2.   

    public class DaffodilNum{
        private int n;
        public DaffodilNum(int n){
            this.n=n;
        }
        public boolean IsOrNot(){
            int a=n%10;
            int b=(n%100-a)/10;
            int c=(n-b*10-a)/100;
            if((Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3))==n) return true;
            return false;
        }
        public static void main(String[] args){
            for(int i=0;i<1000;i++){
                DaffodilNum temp=new DaffodilNum(i);
                if(temp.IsOrNot()) System.out.print(i+" ");
            }
            System.out.println();
        }
    }