Java program for Complex no. Addition.

Hi, I am Aman Kumar pursuing BCA II. I have decided to write what i learn daily.

I request you to please go through this program and feel free to write me if you have any advice/suggestions for me 

at 2022amankumar@gmail.com 



Q. Write a program to add two complex no.

class ComplexNo{    

    //data members

    private int x,y;

    //default constructor

    ComplexNo(){};

    //constructor overloading

    ComplexNo(int a)

    {   x=a;y=a;

    }

    ComplexNo(int a,int b)

    {

        x=a;y=b;

    }

   // method to calculate additon

    void add(ComplexNo no1)

    {

        int real_part,imaginary_part;

        real_part=this.x+no1.x;

        imaginary_part=this.y+no1.y;

        System.out.println(real_part+" + i"+imaginary_part);

    }

                

class LearnAndBlog

{

public static void main (String[] args) throws java.lang.Exception

{

        //You can customize main section as per your choice

ComplexNo case1,case2;

        case1=new ComplexNo(1,2);

        int a,int b;

        a=Integer.parseInt(args[0]);

        b=Integer.parseInt(args[1);

        case2=new ComplexNo(a,b);

        case1.add(case2);

}

}


Comments