title: Matching pairs of array
body: <p>I have an array with integers, I just have to count the pairs and return that counted value.</p>
  
  <pre><code>static int StockMerchant(int n , int arr[]){
      int[] temp = new int[n];
      int count = 0;
      for(int i =0  ; i&lt;n ; i++){
              for(int j= i+1 ; j&lt;n ; j++){
  
                  if(arr[i]==arr[j]){
  
                     arr[j] = '0';
                     arr[i] ='0';
                     count++;
                  }
              }
  
  
      }
          return count;
  }
  </code></pre>
  
  <p>when I try:                      <code>1 1 2 2 2</code>: gives output 2</p>
  
  <p>But when I change the input to    <code>1 2 1 2 2</code>: gives output 3</p>
  
  <p>I want the output to be 2 in the second case also. please help.</p>