Ask Question
21 May, 16:50

A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i. e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon is:

Area = (n * s²) / (4 * tan (π/n))

Write a method that returns the area of a regular polygon using the following header:

public static double area (int n, double side)

Write a main method that prompts the user to enter the number of sides and the side of a regular polygon and displays its area.

+2
Answers (1)
  1. 21 May, 19:29
    0
    import java. util. Scanner;

    public class polygon {

    /* * Main Method * /

    public static void main (String[] args) {

    Scanner input = new Scanner (System. in); / / Create a Scanner

    / / Prompt the user to enter the number of sides

    / / and the side of a regular polygon

    System. out. print ("Enter the number of sides: ");

    int n = input. nextInt ();

    System. out. print ("Enter the side: ");

    double side = input. nextDouble ();

    / / Display the area of the regular polygon

    System. out. println ("The area of the polygon is " + area (n, side));

    }

    /* * Method area computes and returns the area of a regular polygon * /

    public static double area (int n, double side) {

    return (n * Math. pow (side, 2) / (4 * Math. tan (Math. PI / n)));

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i. e., the polygon ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers