Lab 12-19-2005 Class Parameter"
package abc;
public class complex {
double real;
double imag;
public complex()
{
real=0;
imag=0;
}
public complex(double re,double im)
{
this.real = re;
this.imag = im;
}
public double real()
{
return real;
}
public double imag() {
return imag;
}
public void add(complex cccc)
{
this.real=this.real+cccc.real;
this.imag=this.imag+cccc.imag;
}
public static void main(String[] args) {
complex cc1=new complex(5,4);
complex cc2=new complex(2,2);
cc1.add(cc2);
System.out.println(""+cc1.real+"+("+cc1.imag+")i");
}
}
public class complex {
double real;
double imag;
public complex()
{
real=0;
imag=0;
}
public complex(double re,double im)
{
this.real = re;
this.imag = im;
}
public double real()
{
return real;
}
public double imag() {
return imag;
}
public void add(complex cccc)
{
this.real=this.real+cccc.real;
this.imag=this.imag+cccc.imag;
}
public static void main(String[] args) {
complex cc1=new complex(5,4);
complex cc2=new complex(2,2);
cc1.add(cc2);
System.out.println(""+cc1.real+"+("+cc1.imag+")i");
}
}
0 Comments:
張貼留言
<< Home