Given two strings representing two complex numbers.
You need to return a string representing their multiplication. Note i2 = -1 according to the definition.
Example 1:
Input: "1+1i", "1+1i" Output: "0+2i" Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.
Example 2:
Input: "1+-1i", "1+-1i" Output: "0+-2i" Explanation: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i.
public String complexNumberMultiply(String a, String b) {
String[] aa = a.split("\\+");
String[] bb = b.split("\\+");
int A = Integer.parseInt(aa[0]);
int B = Integer.parseInt(aa[1].replace("i", ""));
int C = Integer.parseInt(bb[0]);
int D = Integer.parseInt(bb[1].replace("i", ""));
String result = (A * C - B * D) + "+" + (A * D + B * C) + "i";
return result;
}