写的是一个1到1000的水仙花数,也就是象这样的数:153=1的立方+5的立方+3的立方等于这个数 ,大哥门帮我看看 哪错了我急呀
package pck;
public class Test
{
    
 public static void main(String[] args){
   int one,two,three;
   boolean b=true;
   for(int i=0;i<1000;i++){
   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)
     System.out.println(i);
   }
    
    }
}

解决方案 »

  1.   

    还有那个if语句明显是反了,怎么说也应该是==i再输出
      

  2.   

    呵呵,清理下:
    1 所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。
      所以你的程序I应该从100开始
    2 if((one*one*one+two*two*two+three*three*three)!=i) 逻辑错误,
      应该是if((one*one*one+two*two*two+three*three*three)==i)
      

  3.   

    另外,你的代码应该多用写API类,,,毕竟好看些
      

  4.   

    public class Test
    {
        
     public static void main(String[] args){
       int one,two,three;
       boolean b=true;
       for(int i=100;i<1000;i++){
       one=i%10;
       two=(i%100-one)/10;
       three=(i-one-two*10)/100;
      
     if(i==one*one*one+two*two*two+three*three*three)
         System.out.println(i);
      
        
       }
    }
    }
    ok 的代码!!!
      

  5.   

    boolean b=true;//有用吗??
    呵呵...
      

  6.   

    我觉的没必要那样取各位数字啊:
    one=i/100;  //百位
    two=i%100/10; //十位
    three=i%10; //个位
      

  7.   

    正确的程序:
       public class Test
    {
        
     public static void main(String[] args){
       int one,two,three;
       boolean b=true;
       for(int i=100;i<1000;i++){
       one=i%10;
       two=(i%100-one)/10;
       three=(i-one-two*10)/100;
      
     if(i==one*one*one+two*two*two+three*three*three)
         System.out.println(i);
       }
        
        }
    }
      

  8.   

    迷糊,我觉得这个
     one=i%10;
       two=(i%100-one)/10;
       three=(i-one-two*10)/100;
    好麻烦啊
    这样比较容易理解
    one=i/100;  
    two=i%100/10;
    three=i%10;
      

  9.   

    还有这句话   boolean b=true;
    还是个迷糊
    b是什么东东?