public class Solution {
public String complexNumberMultiply(String a, String b) {
Scanner scA = new Scanner(a).useDelimiter("\\+|i");
Scanner scB = new Scanner(b).useDelimiter("\\+|i");
int num1 = scA.nextInt();
int num2 = scA.nextInt();
int num3 = scB.nextInt();
int num4 = scB.nextInt();
StringBuilder sb = new StringBuilder();
sb.append(num1 * num3 - num2 * num4).append('+').append(num1 * num4 + num2 * num3).append('i');
scA.close();
scB.close();
return sb.toString();
}
}
public class Solution {
public String complexNumberMultiply(String a, String b) {
int i = Integer.valueOf(a.substring(0, a.indexOf('+')));
int j = Integer.valueOf(a.substring(a.indexOf('+')+1, a.length()-1));
int k = Integer.valueOf(b.substring(0, b.indexOf('+')));
int l = Integer.valueOf(b.substring(b.indexOf('+')+1, b.length()-1));
return i*k-(j*l)+"+"+(i*l+j*k)+"i";
/*
StringBuilder sb = new StringBuilder();
sb.append(i*k - j*l).append("+").append(i*l+j*k).append("i");
return sb.toString();
*/
}
}