public static double getWind(double x) {
double[] arr = {0.0, 22.5, 45, 67.5, 90, 112.5, 135, 167.5, 180, 202.5, 225, 247.5, 270, 292.5, 315, 337.5};
double minDifference = Math.abs(arr[0] - x);
int minIndex = 0;
for (int i = 1; i < arr.length; i++) {
double temp = Math.abs(arr[i] - x);
if (temp < minDifference) {
minIndex = i;
minDifference = temp;
}
}
return arr[minIndex];
}
根据目标值获取一组数据中,离目标值最接近的数
于 2022-06-02 17:56:06 首次发布