title: Finding the indices of the two items whose price adds up to a value in an Array
body: <p>I'm trying to solve Google code jam questions.</p>
  
  <blockquote>
    <p><strong>Problem</strong></p>
    
    <p>You receive a credit C at a local store and would like to buy two
    items. You first walk through the store and create a list L of all
    available items. From this list you would like to buy two items that
    add up to the entire value of the credit. The solution you provide
    will consist of the two integers indicating the positions of the items
    in your list (smaller number first).</p>
    
    <p><strong>Input</strong></p>
    
    <p>The first line of input gives the number of cases, N. N test cases
    follow. For each test case there will be:</p>
    
    <p>One line containing the value C, the amount of credit you have at the
    store. One line containing the value I, the number of items in the
    store. One line containing a space separated list of I integers. Each
    integer P indicates the price of an item in the store. Each test case
    will have exactly one solution. Output</p>
    
    <p>For each test case, output one line containing "Case #x: " followed by
    the indices of the two items whose price adds up to the store credit.
    The lower index should be output first.</p>
  </blockquote>
  
  <p>I did this so far. However when I put <em>100 , 3 , 5 , 75 , 25</em> as input I get <em>1,22,1</em> as ouput since it iterates through the array for a second time. How can I get <em>1,2</em> as output?</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Main {
  
      public static void main(String[] args) {
          Scanner in = new Scanner(System.in);
  
          int credit = in.nextInt();
  
          int number = in.nextInt();
  
          int[] items = new int[number];
          for (int i = 0; i &lt; number; i++){
              items[i] = in.nextInt();
          }
  
          for (int i = 0; i &lt; number; i++){
              for (int j = 0; j &lt; number; j++){
                  if (items[i] + items[j] == credit){
                      System.out.print(i + "," + j + " ");
                  }
              }
          }
      }
  }
  </code></pre>