Removing a number from array without changing its arithmetic mean | Java program to remove a number from the array without changing its arithmetic mean ; Function to remove a number from the array without changing its arithmetic mean ; Find sum of all elements ; If mean is an integer ; Check if mean is present in the array or not ; Driver code
import java . io . * ; class GFG { static int FindElement ( int a [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + a [ i ] ; if ( sum % n == 0 ) { int m = sum / n ; for ( int i = 0 ; i < n ; i ++ ) if ( a [ i ] == m ) return m ; } return - 1 ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = a . length ; System . out . print ( FindElement ( a , n ) ) ; } }