package c;
public class XT {
public static void main(String[] args) {
complex c1,c2;
c1=new complex(1,2);
c2=new complex(3,4);
complex.toString(complex.add(c1,c2));
}
}
class complex{
private float RealPart,ImaginaryPart;
public complex(float R,float I) {
this.RealPart=R;
this.ImaginaryPart=I;
}
public complex() {
RealPart=0;
ImaginaryPart=0;
}
public static complex add(complex a,complex b) {
complex c=new complex();
c.RealPart=a.RealPart+b.RealPart;
c.ImaginaryPart=a.ImaginaryPart+b.ImaginaryPart;
return c;
}
public static void toString(complex a) {
System.out.println(a.RealPart+"+"+"("+a.ImaginaryPart+")"+"*i");
}
}
这段代码是一个简单的Java程序,用于执行复数的加法操作。它包含两个类:`XT`和`complex`。
`XT`类是主类,其中包含了`main`方法作为程序的入口点。在`main`方法