当前位置:网站首页>1051 Multiplication of Complex Numbers (15 points)
1051 Multiplication of Complex Numbers (15 points)
2022-08-11 07:47:00 【dumb bit】
题目要求:
代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//輸入
Scanner scanner = new Scanner(System.in);
double r1 = scanner.nextDouble();
double p1 = scanner.nextDouble();
double r2 = scanner.nextDouble();
double p2 = scanner.nextDouble();
double a = r1 * Math.cos(p1);
double b = r1 * Math.sin(p1);
double c = r2 * Math.cos(p2);
double d = r2 * Math.sin(p2);
//(a+bi)*(c+di) = ac + adi +bci -bd = (ac-bd) + (ad+bc)i
double s = a * c - b * d;
String sb = "-0.00".equals(String.format("%.2f",s)) ? "0.00" : String.format("%.2f",s);
double x = a * d + b * c;
String xb = x >= 0 ? (String.format("+%.2fi", x)) : (String.format("%.2fi", x));
if ("-0.00i".equals(xb)) {
xb = "+0.00i";
}
System.out.println(sb + xb);
}
}
结果:
边栏推荐
猜你喜欢

恒源云-Pycharm远程训练避坑指南

1091 N-自守数 (15 分)

Implementation of FIR filter based on FPGA (5) - FPGA code implementation of parallel structure FIR filter

Douyin API interface

1036 跟奥巴马一起编程 (15 分)

Discourse's Close Topic and Reopen Topic

Resolved EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo

接口测试的基础流程和用例设计方法你知道吗?

【LaTex-错误和异常】\verb ended by end of line.原因是因为闭合边界符没有在\verb命令所属行中出现;\verb命令的正确和错误用法、verbatim环境的用法

数仓开发知识总结
随机推荐
1096 大美数 (15 分)
1081 检查密码 (15 分)
Multiscale communication in cortical-cortical networks
流式结构化数据计算语言的进化与新选择
【软件测试】(北京)字节跳动科技有限公司终面HR面试题
tf.reduce_mean()与tf.reduce_sum()
JVM学习——3——数据一致性
接入网、承载网、核心网是什么,交换机路由器是什么、这个和网络的协议有什么关系呢?
Internet phone software or consolidation of attack must be "free" calls security clearance
oracle19c不支持实时同步参数,请教一下大佬们有什么好的解决办法吗?
Redis测试
Unity开发者必备的C#脚本技巧
Shell:三剑客之awk
1071 小赌怡情 (15 分)
Tidb二进制集群搭建
LeetCode brushing series -- 46. Full arrangement
从何跟踪伦敦金最新行情走势?
TF中的四则运算
TF中的One-hot
What are the things that should be planned from the beginning when developing a project with Unity?How to avoid a huge pit in the later stage?