public Pair findSubArray(int input[],int sum){
        int currentSum = 0;
        Pair p = new Pair();
        p.start = 0;
        for(int i=0; i < input.length; i++){
            currentSum += input[i];
            p.end = i;
            if(currentSum == sum){
                return p;
            }else if(currentSum > sum){
                int s = p.start;
                while(currentSum  > sum){
                    currentSum -= input[s];
                    s++;
                }
                p.start = s;
                if(currentSum == sum){
                    return p;
                }
            }
        }
        return null;
    }
http://www.geeksforgeeks.org/find-subarray-with-given-sum/
src/com/interview/array/SubarrayWithGivenSum.java