首页 > 代码库 > 100到简单加减乘除算法的程序
100到简单加减乘除算法的程序
public
class
Complex {
double
real;
double
image;
Complex(){
Scanner input =
new
Scanner(System.in);
double
real = input.nextDouble();
double
image = input.nextDouble();
Complex(real,image);
}
private
void
Complex(
double
real,
double
image) {
this
.real = real;
this
.image = image;
}
Complex(
double
real,
double
image){
this
.real = real;
this
.image = image;
}
public
double
getReal() {
return
real;
}
public
void
setReal(
double
real) {
this
.real = real;
}
public
double
getImage() {
return
image;
}
public
void
setImage(
double
image) {
this
.image = image;
}
Complex add(Complex a){
double
real2 = a.getReal();
double
image2 = a.getImage();
double
newReal = real + real2;
double
newImage = image + image2;
Complex result =
new
Complex(newReal,newImage);
return
result;
}
Complex sub(Complex a){
double
real2 = a.getReal();
double
image2 = a.getImage();
double
newReal = real - real2;
double
newImage = image - image2;
Complex result =
new
Complex(newReal,newImage);
return
result;
}
Complex mul(Complex a){
double
real2 = a.getReal();
double
image2 = a.getImage();
double
newReal = real*real2 - image*image2;
double
newImage = image*real2 + real*image2;
Complex result =
new
Complex(newReal,newImage);
return
result;
}
Complex div(Complex a){
double
real2 = a.getReal();
double
image2 = a.getImage();
double
newReal = (real*real2 + image*image2)/(real2*real2 + image2*image2);
double
newImage = (image*real2 - real*image2)/(real2*real2 + image2*image2);
Complex result =
new
Complex(newReal,newImage);
return
result;
}
public
void
print(){
if
(image >
0
){
System.out.println(real +
" + "
+ image +
"i"
);
}
else
if
(image <
0
){
System.out.println(real +
""
+ image +
"i"
);
}
else
{
System.out.println(real);
}
}
}
100到简单加减乘除算法的程序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。