Complex Number Multiplication
阿新 • • 發佈:2017-08-26
pri class ply rgs parse logs nbsp num pan
public class ComplexNumberMultiplicationSolution { public static String complexNumberMultiply(String a, String b) { int p1 = Integer.parseInt(a.split("\\+")[0]); int n1 = Integer.parseInt(a.split("\\+")[1].split("i")[0]); int p2 = Integer.parseInt(b.split("\\+")[0]);int n2 = Integer.parseInt(b.split("\\+")[1].split("i")[0]); int p = p1 * p2 - n1 * n2; int n = p1 * n2 + p2 * n1; String strP = String.valueOf(p); String strN = String.valueOf(n); System.out.println(p1); System.out.println(n1); System.out.println(p2); System.out.println(n2); System.out.println(strP+ "+" + strN + "i"); return null; } public static void main(String[] args) { ComplexNumberMultiplicationSolution complexNumberMultiplicationSolution = new ComplexNumberMultiplicationSolution(); complexNumberMultiplicationSolution.complexNumberMultiply("1+2i", "3+4i"); } }
Complex Number Multiplication