集合S中与K的差值最小的数,找出来,不知道你说的中位数是不是这个意思.
---------------------------------------------------------------------
import java.util.HashSet;
public class Test1 {
public static void main(String[] args) {
HashSet set = new HashSet();
int[] array = new int[10];
// 作成十个100以内的随机数
while (set.size() < 10) {
int ran = (int) (Math.random() * 1000);
set.add(ran % 100 + 1);
}
Integer[] intArray = (Integer[]) set.toArray(new Integer[0]);
for (int i = 0; i < array.length; i++) {
array[i] = intArray[i];
}
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + ",");
}
System.out.println();
// k