2016-09-21 8 views
1

私は、ペンタゴンの半径をとって一面に変えて出力するコードを書こうとしていました。道のりのどこかで、私の数学クラスの使用は間違っています。 (このサイトは初めてしかし、あなたは私のプログラムを理解できるように、すべてのものをフォーマットしようとした)ペンタゴンのエリア

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

間違って出力されたと仮定すると、すべてがコンパイルされ、正常に動作。 –

答えて

1

はそれがside = (2 * radius) * (Math.sin(Math.PI/2/5));ではないでしょうか?

エラーは何ですか。ちょうど間違った答え?

私はこれを試してみてください。

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

...、これは右長さを用いて、式なく半径

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

+0

おかげで、それは完璧に働いた。 –

+0

簡単な質問です。領域の値が表示されているので、これの単位の種類は何ですか?この平方メートルはデフォルトですか? – chitgoks