title: Finding the number of distinct pairs of integers that sum up to an integer
body: <p>I am trying to count the numbers of pairs in an array such that each pair gives the sum of an integer!</p>
  
  <p>I used the following code :</p>
  
  <pre><code>    public static int SumPairs(Integer []input, int k){
      Map&lt;Integer, Integer&gt; pairs = new HashMap&lt;Integer, Integer&gt;();
      int tmp=0;
      //System.out.println(pairs.toString());
       for(int i=0;i&lt;input.length;i++){
       if(pairs.containsKey(input[i])){
              System.out.println(pairs.containsKey(input[i]));
               System.out.println(input[i] +", "+ pairs.get(input[i]));
               input[i]=0; 
              tmp++;      
  
          }
  
          else
              pairs.put(k-input[i], input[i]);
      }return tmp;
  }
  </code></pre>
  
  <p>the problem is ; for example when my array is <code>1 2 2 2 3 4 4 4</code> 
  and  <code>sum = 5</code> 
  it compute as following </p>
  
  <pre><code>(4,1)
  (4,1)
  (4,1)
  (3,2)
  </code></pre>
  
  <p>I want to prevent the method from using a number more than once !!
  so the output will be </p>
  
  <pre><code>(4,1)
  (3,2)
  </code></pre>