Find three vertices in an N | Java program for the above approach ; Function to find three vertices that subtends an angle closest to A ; Stores the closest angle to A ; Stores the count of edge which subtend an angle of A ; Iterate in the range [ 1 , N - 2 ] ; Stores the angle subtended ; If absolute ( angle - A ) is less than absolute ( mi - A ) ; Update angle to mi , and also update i to ans ; Print the vertices ; Driver Code
import java . io . * ; class GFG { static void closestsAngle ( int N , int A ) { double mi = Integer . MAX_VALUE ; int ans = 0 ; for ( int i = 1 ; i < N - 1 ; i ++ ) { double angle = 180.0 * i / N ; if ( Math . abs ( angle - A ) < Math . abs ( mi - A ) ) { mi = angle ; ans = i ; } } System . out . print ( 2 + " ▁ " + 1 + " ▁ " + ( 2 + ans ) ) ; } public static void main ( String [ ] args ) { int N = 3 , A = 15 ; closestsAngle ( N , A ) ; } }