In an array first we have to find whether a desired number exists in that or not? If not then how will I find nearer number to the given desired number in Java?
If the array is sorted, then do a modified binary search. Basically if you do not find the number, then at the end of search return the lower bound.