I asked one question on code review yesterday about my code style, logic and readability of code. Hence, today I kept all those suggestions in mind while solving a new problem question.The question is such: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution.For example: given array S = {-1 2 1 -4}, and target = 1.The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).This is my solution: public int threeSumClosest(int[] num, int target) {    if(num.length < 3) {        return 0;    }      Arrays.sort(num);    int tempSum = Math.abs( target - ( num[0] + num[1] + num[2] ));    int result = num[0] + num[1] + num[2];    for (int index = 0; index < num.length - 1; index++) {        int j = index + 1;        int k = num.length-1;        while (j < k){            int newSum = Math.abs( target - ( num[index] + num[j] + num[k] ) );            if( newSum == 0 ) {                return ( num[index] + num[j] + num[k] ) ;            }            else if ( num[index] + num[j] + num[k] < target ) {                if( newSum < tempSum ) {                    tempSum = newSum;                    result = num[index] + num[j] + num[k];                }                j++;            }            else {                if( newSum < tempSum ) {                    tempSum = newSum;                    result = num[index] + num[j] + num[k];                }                k--;            }        }//end of while loop    }// end of for loop    return result;}It would be great to hear back if I need to make further improvements. Any help will be highly appreciated. Also, Is there an approach which can solve this problem in less than \$O(n^2)\$. 
Finding a sum of unique triplet that is close to a given number in an array
java;programming challenge