Lab 12-19-2005 Class Parameter
package untitled14;
public class add {
public static void main(String[] args) {
complex x = new complex(2, 3);
complex y = new complex(4, 5);
x.add(y);
System.out.println("ans:" + x.a + "+" + y.b + "i");
}
}
---------------------------------------------------------------
package untitled14;
public class complex {
int a = 0, b = 0;
public complex(int a, int b) {
setComplex(a, b);
}
public void setComplex(int a, int b) {
this.a = a;
this.b = b;
}
public void add(complex Q1) {
this.a = this.a + Q1.a;
this.b = this.b + Q1.b;
}
}
public class add {
public static void main(String[] args) {
complex x = new complex(2, 3);
complex y = new complex(4, 5);
x.add(y);
System.out.println("ans:" + x.a + "+" + y.b + "i");
}
}
---------------------------------------------------------------
package untitled14;
public class complex {
int a = 0, b = 0;
public complex(int a, int b) {
setComplex(a, b);
}
public void setComplex(int a, int b) {
this.a = a;
this.b = b;
}
public void add(complex Q1) {
this.a = this.a + Q1.a;
this.b = this.b + Q1.b;
}
}
0 Comments:
張貼留言
<< Home