public int count(int arr[],int k){
        Arrays.sort(arr);
        int count = 0;
        for(int i=0; i < arr.length; i++){
            boolean result = binarySearch(arr, i+1, arr.length-1, arr[i] + k);
            if(result){
                count++;
            }
        }
        return count;
    }
http://www.geeksforgeeks.org/count-pairs-difference-equal-k/
src/com/interview/binarysearch/CountNDistinctPairsWithDifferenceK.java