Java Report

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

import java.util.

*;

public class ComplexNum{


int real, imag;
ComplexNum(int r, int i) //Contructor
{ this.real=r;
this.imag=i;
}
public static ComplexNum add(ComplexNum t1, ComplexNum t2)
{
ComplexNum temp = new ComplexNum(0,0);
temp.real= t1.real+t2.real;
temp.imag= t1.imag+t2.imag;
return temp;
}
public static ComplexNum subtract(ComplexNum t1, ComplexNum t2)
{
ComplexNum temp = new ComplexNum(0,0);
temp.real= t1.real-t2.real;
temp.imag= t1.imag-t2.imag;
return temp;
}
public static ComplexNum multiply(ComplexNum t1, ComplexNum t2)
{
ComplexNum temp = new ComplexNum(0,0);
temp.real= t1.real*t2.real;
temp.imag= t1.imag*t2.imag;
return temp;
}
public static void main(String args[]){
ComplexNum c1= new ComplexNum(10,6), c2= new ComplexNum(5,3);
System.out.print("Addition = ");
ComplexNum temp = add(c1,c2);
System.out.println(temp.real + " " + temp.imag);
System.out.print("Subtraction = ");
temp = subtract(c1,c2);
System.out.println(temp.real + " " + temp.imag);
System.out.print("Multiplication = ");
temp = multiply(c1,c2);
System.out.println(temp.real + " " + temp.imag);

You might also like