[求助]两个复数相減居然会出错,郁闷~
我的源程序如下:public class fushu1
{
int real;
int imag;
void set(int real,int imag)
{
this.real=real;
this.imag=imag;
}
void print()
{
System.out.println(real+"+"+imag+"i");
}
void add(fushu1 a1,fushu1 a2)
{
a1.real=a1.real+a2.real;
a1.imag=a1.imag+a2.imag;
System.out.println(a1.real+"+"+a1.imag+"i");
// return a1;
}
void minus(fushu1 a1,fushu1 a2)
{
a1.real=a1.real-a2.real;//System.out.println(a2.real);
a1.imag=a1.imag-a2.imag;
System.out.println(a1.real+"+"+a1.imag+"i");
// return a1;
}
public boolean compore(fushu1 a1,fushu1 a2)
{
if (a1.real>a2.real)
return true;
else
return false;
/*if (a1.real>a2.real)
return true;
//System.out.println(a1+">"+a2);
else if(a1.real<a2.real)
return false;
//System.out.println(a1+"<"+a2);
else if(a1.real=a2.real)
{
if(a1.imag>a2.imag)
//System.out.println(a1+">"+a2);
else if(a1.imag<a2.imag)
System.out.println(a1+"<"+a2);
else
System.out.println(a1+"<"+a2); }
return ;*/
}
public static void main(String args[])
{
fushu1 f=new fushu1();
fushu1 f1=new fushu1();
fushu1 f2=new fushu1();
f.set(4,7);
f.print();
f1.set(2,9);
f1.print();
f2.add(f,f1);
//f2.print();
f2.minus(f,f1);
//f2.print();
f2.compore(f,f1);
System.out.println("f.real,f1.real "+f2.compore(f,f1));
//f.print();
}
}
红色部分得不出我要的结果~各位大虾看看喔