编写一个程序,提示输入三角形的边长并报告三个角。
我没有得到等于180的角度,并且在某些情况下,我得到NaN的某些角度值。
我的代码如下所示
public static int getSideA() {
System.out.println("What is the length of side a?");
Scanner console = new Scanner(System.in);
int a = console.nextInt();
return a;
}
public static int getSideB() {
System.out.println("What is the length of side b?");
Scanner console = new Scanner(System.in);
int b = console.nextInt();
return b;
}
public static int getSideC() {
System.out.println("What is the length of side C");
Scanner console = new Scanner(System.in);
int c = console.nextInt();
return c;
}
public static void giveSides(int a, int b, int c) {
double angleA = Math.toDegrees(Math.acos((a^2 - b^2 - c^2) / (-2.0 * c * b)));
double angleB = Math.toDegrees(Math.acos((b^2 - a^2 - c^2) / (-2.0 * a * c)));
double angleC = Math.toDegrees(Math.acos((c^2 - a^2 - b^2) / (-2.0 * a * b)));
System.out.println("The three angles are: " + angleA + " " + angleB + " " + angleC);
}
public static void main(String[] args) {
int a = getSideA();
int b = getSideB();
int c = getSideC();
giveSides(a, b, c);
}
胡说叔叔
相关分类