public class ComplexNumber{
   //for real and imaginary parts of complex numbers
   double realimg;
    
   //constructor to initialize the complex number
   ComplexNumber(double rdouble i){
    this.real = r;
    this.img = i;
   }
    
   public static ComplexNumber sum(ComplexNumber c1ComplexNumber c2)
   {
    //creating a temporary complex number to hold the sum of two numbers
        ComplexNumber temp = new ComplexNumber(00);
        temp.real = c1.real + c2.real;
        temp.img = c1.img + c2.img;
        
        //returning the output complex number
        return temp;
    }
    public static void main(String args[]) {
    ComplexNumber c1 = new ComplexNumber(5.54);
    ComplexNumber c2 = new ComplexNumber(1.23.5);
        ComplexNumber temp = sum(c1c2);
        System.out.printf("Sum is: "+ temp.real+" + "+ temp.img +"i");
    }
}


Subscribe For Daily Updates

JAVA File IO examples

JAVA Date & Time Progamming Examples

JAVA Collections

Flutter Questions
Android Questions