Median after K additional integers | Java program to find median of an array when we are allowed to add additional K integers to it . ; Find median of array after adding k elements ; sorting the array in increasing order . ; printing the median of array . Since n + K is always odd and K < n , so median of array always lies in the range of n . ; Driver code
import java . util . Arrays ; class GFG { static void printMedian ( int arr [ ] , int n , int K ) { Arrays . sort ( arr ) ; System . out . print ( arr [ ( n + K ) / 2 ] ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 3 , 2 , 8 } ; int k = 3 ; int n = arr . length ; printMedian ( arr , n , k ) ; } }