Write a program in java to input the number of sides of a polygon and then determine whether it is a hexagon, pentagon, rectangle or a triangle. If the number of sides are either one or two then the invalid input message should be displayed. (Input has to be taken by Scanner class)
Answers
Answered by
0
Answer:
import java.util.Scanner;
public class Exercise {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Input the number of sides on the polygon: ");
int ns = input.nextInt();
System.out.print("Input the length of one of the sides: ");
double side = input.nextDouble();
System.out.print("The area is: " + polygonArea(ns, side)+"\n");
}
public static double polygonArea(int ns, double side) {
return (ns * (side * side)) / (4.0 *Math.tan((Math.PI / ns)));
}
}
Hope you got it....
Similar questions