Related questions with answers
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:
Write a method that returns the area of a regular polygon using the following header:
public static double area(1nt $\mathrm{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.
Solution
VerifiedWe need to define two methods: main and area. main method proms the user to enter the number of sides of the polygon and the length of sides of the polygon and prints the area of that polygon. This method is used to test area method. We will use Scanner clas for user input, so we need to import it.
area method takes two arguments n (number of sides) and side (length of each side) and returns the area of the polygon.
import java.util.Scanner;
public class Main {
// main method
public static void main(String[] args) {}
// Returns the area of a pentagon
public static double area(int n, double side){}
}
Create a free account to view solutions
Create a free account to view solutions
Recommended textbook solutions

Intro to Java Programming, Comprehensive Version
10th Edition•ISBN: 9780133761313Y. Daniel Liang
Fundamentals of Database Systems
7th Edition•ISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
Introduction to Algorithms
3rd Edition•ISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
Introduction to Algorithms
4th Edition•ISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. CormenMore related questions
1/4
1/7