代码拉取完成,页面将自动刷新
import static java.lang.Math.*;
/**
* Created by suhuang on 17-4-19.
*/
public class complex {
public static void main (String[] args) {
Complex b = new Complex(2,5);
Complex c = new Complex(3,-4);
System.out.println(b + "+" + c + "=" + b.ComplexAdd(c));
System.out.println(b + "-" + c + "=" + b.ComplexSub(c));
System.out.println(b + "*" + c + "=" + b.ComplexMulit(c));
System.out.println(b + "/" + c + "=" + b.ComplexDiv(c));
}
}
class Complex {
private double R;
private double I;
public Complex (double R, double I){
this.R=R;
this.I=I;
}
public Complex ComplexAdd(Complex a){
return new Complex(R + a.R, I + a.I);
}
public Complex ComplexSub(Complex a){
return new Complex (R - a.R, I - a.I);
}
public Complex ComplexMulit(Complex a){
return new Complex (R*a.R-I*a.I, R*a.I + I*a.R);
}
public Complex ComplexDiv(Complex a){
double d = sqrt(a.R*a.R)+ sqrt(a.I*a.I);
double e = (R * a.I - I * a.R);
return new Complex((R * a.R + I * a.I) / d, round(e / d));
}
public String toString(){
String rtr_str ="";
if(I>0)
rtr_str = "("+R+"+"+I+"i"+")";
if (I==0) {
rtr_str = "(" + R + ")";
}
if (I<0){
rtr_str = "(" + R + I + "i" + ")";
}
return rtr_str;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。