复数四则运算法则 假设 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 21:00:41 浏览: 247
共轭复数的四则运算法则和差的共轭复数等于共轭复数的和差.积的共.ppt
```java
import java.util.Scanner;
public class ComplexNumber {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入第一个复数的实部a和虚部b:");
double a1 = input.nextDouble();
double b1 = input.nextDouble();
System.out.print("请输入第二个复数的实部c和虚部d:");
double c1 = input.nextDouble();
double d1 = input.nextDouble();
// 计算和
double a2 = a1 + c1;
double b2 = b1 + d1;
System.out.println("两个复数的和为:" + a2 + " + " + b2 + "i");
// 计算差
double a3 = a1 - c1;
double b3 = b1 - d1;
System.out.println("两个复数的差为:" + a3 + " + " + b3 + "i");
// 计算积
double a4 = a1 * c1 - b1 * d1;
double b4 = b1 * c1 + a1 * d1;
System.out.println("两个复数的积为:" + a4 + " + " + b4 + "i");
// 计算商
double a5 = (a1 * c1 + b1 * d1) / (c1 * c1 + d1 * d1);
double b5 = (b1 * c1 - a1 * d1) / (c1 * c1 + d1 * d1);
System.out.println("两个复数的商为:" + a5 + " + " + b5 + "i");
}
}
```
阅读全文