今天老爸問我,已知三邊,如何求三個角的角度
於是(當然,代碼不夠嚴謹):
// format的模板
java.text.DecimalFormat df = new java.text.DecimalFormat("#0.000");
Scanner sc = new Scanner(System.in);
System.out.print("輸入邊長a:");
int a = sc.nextInt();
System.out.print("輸入邊長b:");
int b = sc.nextInt();
System.out.print("輸入邊長c:");
int c = sc.nextInt();
// 計算弧度表示的角
double A = Math.acos((b*b + c*c - a*a)/(2.0*b*c));
double B = Math.acos((a*a + c*c - b*b)/(2.0*a*c));
double C = Math.acos((a*a + b*b - c*c)/(2.0*a*b));
// 用角度表示的角
A = Math.toDegrees(A);
B = Math.toDegrees(B);
C = Math.toDegrees(C);
// 格式化數據,保留小數
String tempA = df.format(A);
String tempB = df.format(B);
String tempC = df.format(C);
System.out.println("角度A:"+tempA);
System.out.println("角度B:"+tempB);
System.out.println("角度C:"+tempC);
三角形的角度計算器:
https://tool.520101.com/calculator/sanjiaoxingjiaodu/