Check if all elements of a Circular Array can be made equal by increments of adjacent pairs | Java program to implement the above approach ; Function to check if all array elements can be made equal ; Stores the sum of even and odd array elements ; If index is odd ; Driver Code
import java . util . * ; class GFG { static boolean checkEquall ( int arr [ ] , int N ) { int sumEven = 0 , sumOdd = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i % 2 == 1 ) sumOdd += arr [ i ] ; else sumEven += arr [ i ] ; } if ( sumEven == sumOdd ) return true ; else return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 7 , 3 , 5 , 7 } ; int N = arr . length ; if ( checkEquall ( arr , N ) ) System . out . print ( " YES " + "NEW_LINE"); else System . out . print ( " NO " + "NEW_LINE"); } }