
plz i want code of program to add real numbers and magic numbers in java example this input :- 5+3i-2+3i output:- 3+6i

public class ComplexNumber {
private int a;
private int b;
public ComplexNumber() {
}
public ComplexNumber(int a, int b) {
this.a = a;
this.b = b;
}
public String getComplexValue() {
if (this.b < 0) {
return a + "" + b + "i";
} else {
return a + "+" + b + "i";
}
}
public static String addition(ComplexNumber num1, ComplexNumber num2) {
int a1 = num1.a + num2.a;
int b1 = num1.b + num2.b;
if (b1 < 0) {
return a1 + "" + b1 + "i";
} else {
return a1 + "+" + b1 + "i";
}
}
public static void main(String args[]) {
ComplexNumber com1 = new ComplexNumber(5, 3);
ComplexNumber com2 = new ComplexNumber(-2, 3);
System.out.println(com1.getComplexValue());
System.out.println(com2.getComplexValue());
System.out.println("Addition of Complex Numbers is :"
+ ComplexNumber.addition(com1, com2));
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.