Check if it is possible to create a polygon with given n sides | Java implementation of the approach ; Function that returns true if it is possible to form a polygon with the given sides ; Sum stores the sum of all the sides and maxS stores the length of the largest side ; If the length of the largest side is less than the sum of the other remaining sides ; Driver code
class GFG { static boolean isPossible ( int a [ ] , int n ) { int sum = 0 , maxS = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; maxS = Math . max ( a [ i ] , maxS ) ; } if ( ( sum - maxS ) > maxS ) return true ; return false ; } public static void main ( String [ ] args ) { int a [ ] = { 2 , 3 , 4 } ; int n = a . length ; if ( isPossible ( a , n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }