Minimum increment and decrement by K of each pair elements required to make all array elements equal | Java program for the above approach ; Function to check if its possible to make all array elements equal or not ; Stores the sum of the array ; Traverse the array ; If sum is divisible by N ; Otherwise , not possible to make all array elements equal ; Driver Code ; Given array ; Size of the array
import java . util . * ; class GFG { static void arrayElementEqual ( int arr [ ] , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } if ( sum % N == 0 ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " + "NEW_LINE"); } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 6 , 4 } ; int N = arr . length ; arrayElementEqual ( arr , N ) ; } }