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;}
相關文章
相關標籤/搜索