Ask Question
10 July, 18:53

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.

+1
Answers (1)
  1. 10 July, 22:02
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers