五角大楼的面积

时间:2016-09-21 18:02:13

标签: java math

我试图编写一个代码来获取五边形的半径并将其转换为一边,然后输出该区域。在某些地方我使用数学类是不正确的。 (此网站的新功能,但尝试格式化所有内容,以便您了解我的程序)

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

1 个答案:

答案 0 :(得分:0)

不应该是side = (2 * radius) * (Math.sin(Math.PI/2/5));

你得到的错误是什么?只是错误的答案?

我认为只是一个简单的tpyo,试试这个。

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

...假设这是使用长度而不是半径

的正确公式

http://www.mathopenref.com/polygonregulararea.html