Ass 1 Prac 1
Ass 1 Prac 1
class Complex {
private double real;
private double imag;
// Constructor to initialize complex number
public Complex(double real, double imag) {
this.real = real;
this.imag = imag;
}
// Method to add two complex numbers
public Complex add(Complex other) {
return new Complex(this.real + other.real, this.imag +
other.imag);
}
// Method to display the complex number
public void display() {
System.out.println(this.real + " + " + this.imag + "i");
}
OUTPUT:
Conclusion :
__________________________________________________
__________________________________________________
__________________________________________________
__________________________________________________