Construct an Array of size N in which sum of odd elements is equal to sum of even elements | Java program to Create an array of size N consisting of distinct elements where sum of odd elements is equal to sum of even elements ; Function to construct the required array ; To confirst half , distinct even numbers ; To consecond half , distinct odd numbers ; Calculate the last number of second half so as to make both the halves equal ; Function to construct the required array ; check if size is multiple of 4 then array exist ; function call to conarray ; Driver code
class GFG { static void arrayConstruct ( int N ) { for ( int i = 2 ; i <= N ; i = i + 2 ) System . out . print ( i + " ▁ " ) ; for ( int i = 1 ; i < N - 1 ; i = i + 2 ) System . out . print ( i + " ▁ " ) ; System . out . print ( N - 1 + ( N / 2 ) + "NEW_LINE"); } static void createArray ( int N ) { if ( N % 4 == 0 ) arrayConstruct ( N ) ; else System . out . print ( - 1 + "NEW_LINE"); } public static void main ( String [ ] args ) { int N = 8 ; createArray ( N ) ; } }