public String toString(){
String info=new String();
if(this.getReal()==0)
info=this.getImage()+"i";
else if(this.getReal()==0)
info=this.getReal();这里有错
else if(this.getImage()<0)
info=this.getReal()+this.getReal()+"i";
else
info=this.getReal()+"-"+this.getReal()+"i";
return info;
}
第六行有错,但是我不知道是什么错误?有谁帮我指出来啊。还有,上面的info=this.getImage()+"i";是正确的而info=this.getImage()+'i';是错误的,为什么?

解决方案 »

  1.   

    public String toString(){
    String info=new String();if(this.getReal()==0){
    info=this.getImage()+"i";
    }
    else if(this.getReal()==0){
    info=this.getReal();//你把一个int或Integer型(this.getReal()==0,根据此得出其数据类型)的数据赋给了Stirng,数据类型不一致;修改成info=this.getReal().toStirng();
    }
    else if(this.getImage()<0){
    info=this.getReal()+this.getReal()+"i";
    }
    else{
    info=this.getReal()+"-"+this.getReal()+"i";
    }
    return info;
    }
      

  2.   

    我试了不行的啊,它提示“无法取消应用 double”
      

  3.   

    if(this.getReal()==0){
        info=this.getImage()+"i";
    }else if(this.getReal()==0){
        info=this.getReal
    }去掉上述两个分支中的一个(重复了)。
      

  4.   

    谢谢您啊,我是初学。不过这个我刚才已经修改过了,我现在的程序是这样。
    public String toString(){
    String info=new String();
    if(this.getReal()==0)
    info=this.getImage()+"i";
    else if(this.getImage()==0)
    info=this.getReal()+"I";
    else if(this.getImage()<0)
    info=(this.getReal()).toString()+(this.getImage()).toString()+"i";
    else
    info=this.getReal()+this.getImage()+"i"+5;
    return info;
    }
    错误在第9行,就是我按你的改法修改后提示的“无法取消应用 double”
      

  5.   

    (this.getReal()).toString()
    改为
    String.valueOf(this.getReal())
      

  6.   

    OK,现在没错误了,谢谢你啊。不过为什么info=this.getImage()+"i";这句没错,是不是+将double型的this.getImage()转换成了String型。另外,既然info=this.getImage()+"i";是对的,为甚么info=this.getImage()+’i‘;会报错呢