int myNumber = 490; int distance = 0; int idx = 0; for(int c = 0; c < numbers.length; c++){ int cdistance = numbers[c] - myNumber; if(cdistance < distance){ idx = c; distance = cdistance; } } int theNumber = numbers[idx];
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter