using java. Write a program that prompts for the lengths of the sides of a trian
ID: 3637104 • Letter: U
Question
using java.Write a program that prompts for the lengths of the sides of a triangle and reports the three
angles. HINT: Use the Law of Cosines. angle = arccos (a^2 + b^2 - c^2) / (2ab).
Explanation / Answer
The program given by rapunzel gives a compilation error. I have corrected it. import java.util.*; public class findAnglesOfTriangle {public static void main(String [] args) {double s1,s2,s3,angle1,angle2,angle3; Scanner in = new Scanner(System.in); System.out.print("enter side 1 of triangle: "); s1=in.nextInt(); System.out.print("enter side 2 of triangle: "); s2=in.nextInt(); System.out.print("enter side 3 of triangle: "); s3=in.nextInt(); double max=biggest(s1,s2,s3); if(max==s1) {angle1=getA1(s1,s2,s3); angle2=getA2(s1,s2,angle1); } else if(max==s2) {angle1=getA1(s2,s1,s3); angle2=getA2(s2,s1,angle1); } else {angle1=getA1(s3,s1,s2); angle2=getA2(s3,s1,angle1); } angle3=180-(angle1+angle2); System.out.println(angle1+", "+angle2+", "+angle3+" are the angles of the triangle"); } public static double biggest(double s1, double s2,double s3) {if(s1>s2&&s1>s3) return s1; else if(s2>s1&&s2>s3) return s2; else return s3; } public static double getA1(double c,double a, double b) {return Math.toDegrees(Math.acos((a*a+b*b-c*c)/(2*a*b))); } public static double getA2(double c,double a, double a1) {return Math.toDegrees(Math.asin(a*Math.sin(Math.toRadians(a1))/c)); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.