java 537.复数乘法(1st).java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 537.复数乘法(1st).java相关的知识,希望对你有一定的参考价值。

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();
        */
    }
}

以上是关于java 537.复数乘法(1st).java的主要内容,如果未能解决你的问题,请参考以下文章

java 537.复数乘法(1st).java

java 537.复数乘法(1st).java

java 537.复数乘法(1st).java

java 537.复数乘法(1st).java

c_cpp 537.复数乘法

字符串537. 复数乘法