作业帮 > 综合 > 作业

16.写出以下程序段的输出结果.

来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/07/18 14:34:00
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.写出以下程序段的输出结果.
运行结果:
1.2 - 1.5i