第1个回答 2016-03-17
double[] arr = new double[10];
double sum = 0;
for (int i = 0; i < arr.length; i++) {
arr[i] = Math.random();
sum += arr[i];
}
double average = sum / arr.length;
Arrays.sort(arr);
int i = Arrays.binarySearch(arr, average);
if (i < 0) {
i = -i - 1;
if (arr[i] - average > average - arr[i - 1]) {
i--;
}
}
System.out.println("所求的值:" + arr[i]);本回答被网友采纳