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.
Solution:
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);
}
Saturday, June 21, 2014
Home
Unlabelled
Java Exercise Nr. 47 (Mathematical Functions)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment