Gabriel Tomasetto Gabriel Tomasetto - 1 month ago 5x
Java Question

Area of a Pentagon

I was trying to write a code to take the radius of a pentagon and turn it into a side, then output the area. Somewhere along the way my use of the math class is incorrect. (New to this site but tried to format everything so you could understand my program)

Class: CS 1301/16
// Term: Fall
// Name: Gabriel Tomasetto
// Intsructor: Ms. Tulin
// Assignment 1

import java.util.*;

public class Pentagon {
public static void main(String[] args) {
Scanner scan = new Scanner(;
double radius, side, area;

System.out.println("Please enter the length of the Pentagon from the center to the vertex: ");
radius = scan.nextDouble();

side = (2 * radius) * (Math.sin(Math.PI/5)); //I'm assuming I'm not correctly using the Math class to represent the equation? Thoughts.

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

System.out.println("The area of the Pentagon is:\t" + area);


Shouldn't it be side = (2 * radius) * (Math.sin(Math.PI/2/5));?

What's the error you're getting? Just the wrong answer?

Just a simple tpyo I think, try this.

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

...assuming this is the right formula using side length and not radius