当前位置:网站首页>1051 复数乘法 (15 分)
1051 复数乘法 (15 分)
2022-08-11 06:46:00 【呆比特】
题目要求:
代码:
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);
}
}
结果:
边栏推荐
猜你喜欢
随机推荐
软件测试基本流程有哪些?北京专业第三方软件检测机构安利
Pico neo3在Unity中的交互操作
Pinduoduo API interface (attach my available API)
Activity的四种状态
Implement general-purpose, high-performance sorting and quicksort optimizations
如何选择专业、安全、高性能的远程控制软件
为什么C#中对MySQL不支持中文查询
下一代 无线局域网--强健性
Discourse 的关闭主题(Close Topic )和重新开放主题
Redis测试
关于Android Service服务的面试题
JD.com product details API call example explanation
How to choose professional, safe and high-performance remote control software
2022-08-09 Group 4 Self-cultivation class study notes (every day)
NFT 的价值从何而来
Waldom Electronics宣布成立顾问委员会
TF中的条件语句;where()
Douyin get douyin share password url API return value description
Pico neo3 Unity打包设置
技能在赛题解析:交换机防环路设置