Check if an N | Java program for the above approach ; Function to check if the polygon exists or not ; Initialize a variable to store the sum of angles ; Loop through the array and calculate the sum of angles ; Check the condition for an N - side polygon ; Driver code ; Given array arr [ ] ; Function call
import java . util . * ; class GFG { static void checkValidPolygon ( int arr [ ] , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } if ( sum == 180 * ( N - 2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int N = 3 ; int arr [ ] = { 60 , 60 , 60 } ; checkValidPolygon ( arr , N ) ; } }