Area of a pentagon

 Area of a pentagon

Problem Description


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, where r is the length from the center of a pentagon to a vertex.


(Hint: Length of the side =2*length from the center to a vertex * sine(PI/5)


Area = (5 * Math.pow(side, 2)) / (4 * Math.tan(Math.PI /5));


For rounding to two decimal points uses String.format("%.02f",variablename))


Logic Test Case 1


Input (stdin)

6.4


Expected Output


97.39

Logic Test Case 2


Input (stdin)

5.9


Expected Output


82.77







Code Area

import java.util.*;

import java.util.*;

public class TestClass {

   

    public static void main(String args[])  

    {  

  

      Scanner scan = new Scanner(System.in);

  double radius, side, area;

  radius = scan.nextDouble();

side = (2 * radius) * (Math.sin(Math.PI/5));

  area = (5 * Math.pow(side, 2)) / (4 * Math.tan(Math.PI /5));


  System.out.printf("%.2f", area);

     

   

}

}

Post a comment

0 Comments