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 toStri

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 17:28:38
16.写出以下程序段的输出结果.classComplexextendsObject{privatedoublex,y;Complex(doubleu,doublev){x=u;y=v;}doubler

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 toStri
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());
}
}

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 toStri
运行结果:
1.2 - 1.5i