我有这个方法来获得中值,
public double getMedian(double[] numberList) {
int factor = numberList.length;
double[] first = new double[(int) factor / 2];
double[] last = new double[first.length];
double[] middleNumbers = new double[1];
for (int i = 0; i < first.length; i++) {
first[i] = numberList[i];
}
for (int i = numberList.length; i >= last.length; i--) {
last[i] = numberList[i];
}
for (int i = 0; i <= numberList.length; i++) {
if (numberList[i] != first[i] || numberList[i] != last[i])
middleNumbers[i] = numberList[i];
}
if (numberList.length % 2 == 0) {
double total = middleNumbers[0] + middleNumbers[1];
return total / 2;
} else {
return middleNumbers[0];
}
}
但给我一个IndexOutOfBounds异常。有人可以帮我解决错误吗?