看看我这个问题出在哪:public class A_3 {
public static void main(String[] args){
int a =0,b =0,c =0;
if((a>0&&a<10)||(b>0&&b<10)||(c>0&&c<10)){
int math = a*100 + b*10 + c;
int lfhe = a*a*a +b*b*b +c*c*c;
for(math = 100;math<1000;math++){
if(math == lfhe)
System.out.println(math);
}
}
}
}

解决方案 »

  1.   

    你没有将3位数的百位,十位,个位 给 分离出来放到 a,b,c里。我给你个例子public class A_3 {


    public static void main(String[] args){

    int a = 0,b = 0,c = 0;
    System.out.println("水仙花数:");
    for(int i=100;i<1000;i++)
    {
    a = i/100; // 百位
    b = i%100/10; // 十位
    c = i%100%10; // 个位
    if(i==a*a*a+b*b*b+c*c*c)
    {
    System.out.print(i+"\t");
    }
    }

    }}
      

  2.   

    public class Test
    {
    static int a,b,c,d;
     public static void main(String [] args)
     {
       
        for(int j=100;j<=999;j++)
      {
      p(j);
      if(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)==j)
      System.out.println(j);
      }
     }
     public  static void p(int i)
     {
      a = i/100;
      d = i%100;
      b = d/10;
      c = d%10;
     }
    }
      

  3.   

    谢谢!
    没有将3位数的百位,十位,个位 给 分离出来放到 a,b,c里?
    我还是觉得我那样写按道理来说是不应该有问题的。我想知道错误的原因?
      

  4.   

    楼主你定义int a =0,b =0,c =0;,然后判断if((a>0&&a<10)||(b>0&&b<10)||(c>0&&c<10))
    a=0,所有a>0&&a<10=false;所以没有结果。
      

  5.   

    楼主这是我写的,先取得个、十、百位,再去拼三位数,然后求结果。
    public class A_3 {
        public static void main(String[] args){
            int a,b,c;
            for(a=1;a<=9;a++)//百位不能为0
            {
                for(b=0;b<=9;b++)
                {
                    for(c=0;c<=9;c++)
                    {
                        int math = a*100 + b*10 + c;
                        int lfhe = a*a*a +b*b*b +c*c*c;
                        if(math == lfhe)
                            System.out.println(math);
                    }
                }
            }    }
    }