Find the length of Kth N | Java program for the above approach ; Function to calculate the interior angle of a N - sided regular polygon ; Function to find the K - th polygon formed inside the ( K - 1 ) th polygon ; Stores the interior angle ; Stores the side length of K - th regular polygon ; Return the length ; Driver Code
import java . util . * ; class GFG { static final double PI = 3.14159265 ; static double findInteriorAngle ( int n ) { return ( ( n - 2 ) * PI ) / n ; } static double calculateSideLength ( double L , int N , int K ) { double angle = findInteriorAngle ( N ) ; double length = L * Math . pow ( Math . sin ( angle / 2 ) , ( K - 1 ) ) ; return length ; } public static void main ( String [ ] args ) { double L = 21 ; int N = 5 , K = 7 ; System . out . print ( calculateSideLength ( L , N , K ) ) ; } }