复数四则运算法则 假设 z1 = a + bi,z2 = c + di 和:z1 + z2 = (a+c) + (b+d)i 差:z1 - z2 = (a-c) + (b-d)i 积:z1 * z2 = (ac-bd) + (bc + ad)i 商:z1 / z2 = (ac + bd)/(c * c+d * d) + (bc-ad)/(c * c+d * d)i 编程要求 根据提示,在右侧编辑器补充代码,计算并输出两个复数的和、差、积、商运算结果。用java写
时间: 2023-04-01 13:00:45 浏览: 156
用C语言实现复数的四则运算
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入第一个复数的实部和虚部:");
double a = scanner.nextDouble();
double b = scanner.nextDouble();
System.out.println("请输入第二个复数的实部和虚部:");
double c = scanner.nextDouble();
double d = scanner.nextDouble();
// 计算和
double sumReal = a + c;
double sumImag = b + d;
System.out.println("和:" + sumReal + " + " + sumImag + "i");
// 计算差
double diffReal = a - c;
double diffImag = b - d;
System.out.println("差:" + diffReal + " + " + diffImag + "i");
// 计算积
double productReal = a * c - b * d;
double productImag = b * c + a * d;
System.out.println("积:" + productReal + " + " + productImag + "i");
// 计算商
double denominator = c * c + d * d;
double quotientReal = (a * c + b * d) / denominator;
double quotientImag = (b * c - a * d) / denominator;
System.out.println("商:" + quotientReal + " + " + quotientImag + "i");
}
}
```
阅读全文