/*This is a java program to find K such elements given by users, such that those numbers are closer to the median of the given sequence. We first find the median of the sequence and then compare with each element such that the difference between the median and number is minimum, and print such k elements.*/ //This is a java program to find k numbers closest to median of N numbers import java.util.Random; import java.util.Scanner; public class K_Close_Numbers_Median { static int N = 25; static int[] sequence = new int[N]; public static void sort() { int i, j, temp; for (i = 1; i < N; i++) { j = i; temp = sequence[i]; while (j > 0 && temp < sequence[j - 1]) { sequence[j] = sequence[j - 1]; j = j - 1; } sequence[j] = temp; } } public static int median() { if(N%2 == 0) return ((sequence[N/2-1] + sequence[N/2])/2); else return sequence[N/2]; } public static void main(String args[]) { Random random = new Random(); for(int i=0; i