title: Java - how to stop nested loops from checking same indices twice?
body: <p>Given an array and a number N call a pair of numbers from the array a Perfect Pair if their sum is equal to N.</p>
  
  <p>Find all of the perfect pairs and return the sum of their indices. Note that any element of the array can only be counted in one Perfect Pair.</p>
  
  <p>Examples</p>
  
  <p>pairwise([1, 4, 2, 3, 0, 5], 7) = 11
  Since the Perfect Pairs are (4, 3) and (2, 5) with indices 1 + 3 + 2 + 5 = 11.</p>
  
  <p>pairwise([1, 3, 2, 4], 4) = 1
  Since the element at index 0 (i.e. 1) and the element at index 1 (i.e. 3) form the only Perfect Pair.</p>
  
  <p>Input 1 (arr) → array.integer :
  array of non-negative integers</p>
  
  <p>Input 2 (N) → integer :
  positive integer</p>
  
  <p>Output → integer :
  sum of indices and 0 if no Perfect Pair exists</p>
  
  <p>My Code:</p>
  
  <pre><code>     public static void main(String[] args) {
          int x[] = {1,4,2,3,0,5};
          System.out.println(pairwise(x, 7)); 
      }
  
       public static int pairwise(int[] arr, int N) {    
          int t=0;
          for(int i=0;i&lt;arr.length;i++){
            for(int k=0;k&lt;arr.length;k++){
              if(arr[i]+arr[k] == N){
                t+=i+k;
              } 
            }
          }
          return t;
       }
  </code></pre>
  
  <p>The problem is my code checks indices twice, like (0,1) and (1,0) are treated like different indices.</p>