16.写出以下程序段的输出结果.
问题描述:
16.写出以下程序段的输出结果.
class Complex extends Object {
private double x,y;
Complex(double u,double v){
x=u;
y=v;
}
double real(){
return x;
}
double imag(){
return y;
}
void plus(Complex w) {
\x05x+=w.real();
\x05y+=w.imag();
}
public String toString() {
if (y>0)
return x+" + "+y+"i";
\x05else
return x+" - "+(-y)+"i";
}
public static void main(String[] args) {
\x05 Complex c1=new Complex(2,1.5);
Complex c2=new Complex(-0.8,-3);
c1.plus(c2);
System.out.println(c1.toString());
}
}
答
运行结果:
1.2 - 1.5i