代码拉取完成,页面将自动刷新
package exp2;
import java.util.Random;
public class Complex
{
private double RealPart;
private double ImagePart;
public Complex(double R,double I)
{
RealPart = R;
ImagePart = I;
}
public boolean equals(Complex obj)
{
boolean result = false;
if (RealPart ==obj.RealPart && ImagePart==obj.ImagePart)
result = true;
return result;
}
public Complex ComplexAdd(Complex obj)
{
RealPart +=obj.RealPart;
ImagePart +=obj.ImagePart;
return new Complex(RealPart,ImagePart);
}
public Complex ComplexSub(Complex obj)
{
RealPart -=obj.RealPart;
ImagePart -=obj.ImagePart;
return new Complex(RealPart,ImagePart);
}
public Complex ComplexMulti(Complex obj)
{
double realpart = RealPart;
RealPart = RealPart*obj.RealPart-ImagePart*obj.ImagePart;
ImagePart = realpart*obj.ImagePart+ImagePart*obj.RealPart;
return new Complex(RealPart,ImagePart);
}
public Complex ComplexDiv(Complex obj)
{
Complex number = new Complex(RealPart,ImagePart);
Complex number2 = new Complex(RealPart,ImagePart);
Complex conjugateobj = new Complex(obj.RealPart,0-obj.ImagePart);
Double denominator = (obj.ComplexMulti(conjugateobj)).RealPart;
RealPart = (number.ComplexMulti(conjugateobj).RealPart)/denominator;
ImagePart = ((number2.ComplexMulti(conjugateobj)).ImagePart)/denominator;
return new Complex(RealPart,ImagePart);
}
public String toString()
{
String result="";
if(ImagePart == 0.0)
result = RealPart+"";
else
if(RealPart==0.0)
result = ImagePart+"i";
else
if(ImagePart>0)
result = RealPart+""+"+"+ImagePart+"i";
else
result = RealPart+""+ImagePart+"i";
return result;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。