aartiyadav
New Coder
Hello Everyone, I am new in this community and new to Java and am attempting to write code that takes the number of sides of a polygon and the length of each side as input and gives the area of the polygon as output. The JRE I am using says that my code will not run, possibly because of an endless loop. I do not see any errors in my code, but I have an untrained eye so any help would be greatly appreciated. I'm using the online compiler on https://www.interviewbit.com/online-java-compiler/ Below is my code.
Java:
import java.util.Scanner;
public class Exercise04_05{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of sides: ");
double num = input.nextInt();
System.out.println("Enter the side: ");
double side = input.nextInt();
double area = (num*side*side) / (4 * Math.tan(Math.PI / num));
System.out.print("the area of the polygon is: " + area);
}
}