0% found this document useful (0 votes)
7 views

Import Java.util.;

Wd

Uploaded by

Narsale Shreyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Import Java.util.;

Wd

Uploaded by

Narsale Shreyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

*;
public class complex {
int real;
int img;
static int ch=0;
complex(){}
complex(int r,int i){
real=r;
img=i;}
public static void main (String []args)
{
complex n1=new complex();
complex n2=new complex();
Scanner sc=new Scanner(System.in);
System.out.println("enter first real complex number:-");
n1.real=sc.nextInt();
System.out.println("enter first imaginary complex number:-");
n1.img=sc.nextInt();
System.out.println("enter second real complex number:-");
n2.real=sc.nextInt();
System.out.println("enter second imaginary complex number:-");
System.out.println("list of operations");
System.out.println("1.Add");
System.out.println("2.subtract");
System.out.println("3.multiply");
System.out.println("4.divide");
System.out.println("");
System.out.println("enter your choice");
ch=sc.nextInt();
switch (ch)

{}
case1:

add(n1,n2);
break;
case2:
sub(n1,n2);
break;
case3:
mul(n1,n2);
break;
case4:
div(n1,n2);

break;
default:
System.out.println("invalid choice");
break;
}
sc.close();

private static void div(complex n1,complex n2)


{
complex r=new complex();
r.real=n1.real/n2.real;
r.img=n1.img/n2.img;
System.out.println("("+r.real+"+"+r.img+"i)");
}
private static void mul(complex n1,complex n2)
{
complex r=new complex();
r.real=n1.real*n2.real;
r.img=n1.img*n2.img;
System.out.println("("+r.real+"+"+r.img+"i)");
}
private static void sub(complex n1,complex n2){
complex r=new complex();
r.real=n1.real-n2.real;
r.img=n1.img-n2.img;
System.out.println("("+r.real+"+"+r.img+"i)");}

private static void add(complex n1,complex n2) {


complex r=new complex();
r.real=n1.real+n2.real;
r.img=n1.img+n2.img;
System.out.println("("+r.real+"+"+r.img+"i)");
}
}

You might also like