-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplex.java
More file actions
49 lines (43 loc) · 870 Bytes
/
Complex.java
File metadata and controls
49 lines (43 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package lihe;
public class Complex {
private double x,y;
public Complex(double real,double imag)
{
x=real;
y=imag;
}
public Complex mul(double x,double y)
{
return new Complex(x*this.x-y*this.y,this.x*y+this.y*x);
}
public static Complex mul(Complex a,Complex b)
{
return new Complex(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);
}
public Complex mul(Complex a)
{
return new Complex(x*a.x-y*a.y,x*a.y+y*a.x);
}
public String toString()
{
return "("+x+","+y+"i"+")";
}
public double qumo()
{
return Math.sqrt(x*x+y*y);
}
//¼Ó·¨£º
//¼Ó·¨£º
//¼Ó·¨£º
public static void main(String[] args)
{
Complex a = new Complex(1,2);
Complex b = new Complex(3,4);
Complex z= a.mul(3,4);
System.out.println("mul:result1="+z);
z = mul(a,b);
System.out.println("mul:result2="+z);
z = a.mul(b);
System.out.println("mul:result3="+z);
}
}