java 查找数组中最接近的一个数字

public static Integer getNumberThree(Integer[] intarray,Integer number){
int index = Math.abs(number-intarray[0]);
int result = intarray[0];
for (int i : intarray) {
int abs = Math.abs(number-i);
if(abs <= index){
index = abs;
result = i;
}
}
return result;
}

转载于:https://www.cnblogs.com/austinspark-jessylu/p/11271525.html

你可能感兴趣的:(java)