问题描述
- 题目:有一系列复数,如3+4i,6-7i,每一个复数可以求出与另外一个复数的和与积。
-
写完这个程序,可以运行,但是同学说我参数设的有问题,我自己不太理解。希望有人能给我指点。
public class Complexnumber {
int real;
int im;
public Complexnumber(int real,int im){
this.real=real;
this.im=im;
}
public void sum(Complexnumber other,Complexnumber t){
t.real=this.real+other.real;
t.im=this.im+other.im;
}
public void multiply(Complexnumber other,Complexnumber t){
t.real=this.real*other.real-this.im*other.im;
t.im=this.real*other.im+other.real*this.im;
}
public void judge(Complexnumber other){
if(other.im<0){
System.out.println(+other.real+"-"+other.im+"i");
}
else if(other.im==0){
System.out.println(+other.real);
}
else{
System.out.println(+other.real+"+"+other.im+"i");
}
}
public static void main(String[] args) {
Complexnumber c1;
c1=new Complexnumber(5,1);
Complexnumber c2;
c2=new Complexnumber(3,6);
Complexnumber t;
t=new Complexnumber(0,0);
c1.sum(c2,t);
c1.judge(t);
c1.multiply(c2,t);
c1.judge(t);
}}
解决方案
http://blog.163.com/jsongde@126/blog/static/136495035201092251525596/
解决方案二:
哪个参数设的不对。我感觉lz的代码写的不错啊
时间: 2025-01-29 17:17:07