```
public class Solution {
public int threeSumClosest(int[] num, int target) {
Arrays.sort(num);
int i = 0, j = 1, k = num.length - 1;
int ans = num[0] + num[1] + num[2];
while(i < j && j < k) {
int s = num[i] + num[j] + num[k];
if( s == target) return s;
else {
if (Math.abs(target - ans) > Math.abs(target - s) ) ans = s;
if (s > target) k--;
else {
if(i < j - 1) i++;
else j++;
}
}
}
return ans;
}
}
```

Above is my buggy code which passed the OJ.

Please add some test cases such as:

```
int[] num = {1, 2, 4, 8, 16, 32, 64, 128};
int target = 82;
```