Find K such that | A | Java implementation of the approach ; Function to find k such that | a - k | = | b - k | ; If ( a + b ) is even ; Driver code
class GFG { static int find_k ( int a , int b ) { if ( ( a + b ) % 2 == 0 ) return ( ( a + b ) / 2 ) ; return - 1 ; } public static void main ( String [ ] args ) { int a = 2 , b = 16 ; System . out . println ( find_k ( a , b ) ) ; } }