public static int findPair(int[] a, int sum) {
        Arrays.sort(a);
        int start = 0;
        int end = a.length-1;
        int total = 0;
        while( start != end){
            if(a[start] + a[end] == sum){
                total += 1;
                start += 1;
            }else if( a[start] + a[end] < sum){
                start += 1;
            }else{
                end -= 1;
            }
        }
        return total;
    }