Gabriel Tomasetto - 1 year ago 336

Java Question

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(System.in);

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);

}

}

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

~~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**

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**