-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconjugate.java
More file actions
41 lines (39 loc) · 1.22 KB
/
Copy pathconjugate.java
File metadata and controls
41 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.*;
class Complexnum {
double real,imaginary;
Complexnum(){}//default constructor
Complexnum(double r, double i){//parametric constructor
this.real=r;
this.imaginary=i;
}
void display(){//method to display complex number...
if(imaginary>=0){
System.out.println(real+" +i "+imaginary);
}
else
System.out.println(real+" -i "+(-imaginary));
}
void objdisplay(){//method to display conjugate of complex number...
if(imaginary>=0){
System.out.println(real+" -i "+imaginary);
}
else{
System.out.println(real+" +i "+(-imaginary));
}
}
}
public class conjugate {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("ENTER THE REAL NUMBER = ");
double r=sc.nextDouble();
System.out.print("ENTER THE IMAGINARY NUMBER = ");
double i=sc.nextDouble();
Complexnum M=new Complexnum(r,i);//M is a object.
System.out.println("GIVEN COMPLEX NUMBER...");
M.display();
System.out.println("CONJUGATE OF COMPLEX NUMBER = ");
M.objdisplay();
sc.close();
}
}