Menu Close

Area of pentagon in Java …ftc

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

Input:
length from  center: 6.4

Output:
Area = 97.39
import java.io.*;
import java.util.*;
import java.lang.Math;
public class temp{
  public static void main(String[] args){
    double verside , side , area;
    Scanner scan = new Scanner(System.in);
    System.out.print("Length from center to vertex:  ");
    verside = scan.nextDouble();

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

    System.out.println("Area of Pentagon:  "+String.format("%.02f",area));
	}
}

INPUT_1:
Length from center to vertex:  6.4

OUTPUT:
Area of Pentagon:  97.39


INPUT_2:
Length from center to vertex:  5.9

OUTPUT:
Area of Pentagon:  82.77


INPUT_3:
Length from center to vertex:  6.3

OUTPUT:
Area of Pentagon:  94.37


INPUT_4:
Length from center to vertex:  5.2

OUTPUT:
Area of Pentagon:  64.29


INPUT_5:
Length from center to vertex:  11.2

OUTPUT:
Area of Pentagon:  298.25


ILLUSTRATION

executed using javac in terminal linux