Write a program that prompts the user to enter the length from the center of a p
ID: 3793629 • Letter: W
Question
Write a program that prompts the user to enter the length from the center of a pentagon to a vertex and computes the area of the pentagon, as shown in the following figure. The formula for computing the area of a pentagon is Area = 5 times s^2/4 times tan(pi/5), where s is the length of a side. The side can be computed using the formula s = 2r sin pi/5, where r is the length from the center of a pentagon to a vertex. Round up two digits after the decimal point. Here is a sample run: Enter the length from the center to a vertex: 5.5 The area of the pentagon is 71.92Explanation / Answer
Answer:
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
double length, side, area;
System.out.print("Enter the length from the center to a vertex:");
length = s.nextDouble();
side = 2 * length * Math.sin(Math.toRadians(36));
area = (5 * Math.pow(side, 2)) / (4 * Math.tan(Math.toRadians(36)));
System.out.printf("The area of the pentagon is %4.2f.", area);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.