Answer:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n;
double side;
char choice;
while(true){
System.out.print("Enter the number of sides: ");
n = input.nextInt();
System.out.print("Enter the side of a regular polygon: ");
side = input.nextDouble();
System.out.println("Area is: " + area(n, side));
System.out.print("Do you want to continue(y/n): ");
choice = input.next().charAt(0);
if(choice == 'n')
break;
}
}
public static double area(int n, double side){
double area = (n * Math.pow(side, 2) / (4 * Math.tan(Math.PI / n)));
return area;
}
}
Step-by-step explanation:
Create a function named area that takes two parameters, n and side
Calculate the area using the given formula
Return the area
In the main:
Create an indefinite while loop. Inside the loop:
Ask the user to enter the n and side
Call the area() function passing the n and side as parameters and print the result
Ask the user to continue or not. If the user enters "n", stop the loop