📄 complexnumber.java
字号:
public class Complexnumber{
public double realpart=0.0f;
public double imgpart=0.0f;
public Complexnumber(){realpart=0.0;imgpart=0.0;}
public Complexnumber(double r,double i)
{realpart=r;imgpart=i;}
public void Add(Complexnumber t)
{this.realpart+=t.realpart;
this.imgpart+=t.imgpart;
}
public void Sub(Complexnumber t)
{this.realpart-=t.realpart;
this.imgpart-=t.imgpart;
}
public void Add( double r)
{this.realpart+=r;}
public void Sub( double r)
{this.realpart-=r;}
public String toString( )
{return "\nrealpart="+realpart+"\nimgpart="+imgpart;
}
public static void main(String[] args)
{Complexnumber a=new Complexnumber(1,2);
Complexnumber b=new Complexnumber(-1,-1);
System.out.println("A:"+a);
System.out.println("B:"+b);
a.Add(b);
System.out.println("A+B:"+a);
a.Add(2);
System.out.println("A+2:"+a);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -