title: "integer number too long" Error when my method takes a long (Java)
body: <p>I have a sorted array of contacts and each object has a Name(string) and phone Number(long). I am using a binary search method that returns the index of the contact with the same number that the user inputs. Even though my Binary search takes a long as parameter, when I call the method, it treats it as an int. So, if I put a number that is greater than the int max limit, I get an error saying that the integer is too long.</p>
  
  <p>I was just testing my code by trying to run the method with a phone number from the array</p>
  
  <pre><code>System.out.println(binarySearch(contacts,9077867820,0,1000));
  </code></pre>
  
  <p>And it throws a "integer too large" error. When I try it again with a number that is less than the int max limit like this: </p>
  
  <pre><code>System.out.println(contacts[binarySearch(contacts,1171652637,0,1000)]);
  </code></pre>
  
  <p>It returns the index of the contact in the array. </p>
  
  <p>Here is my method: </p>
  
  <pre><code>public static int binarySearch(Contact[] A, long key, int low, int high)
  {
      int rangeSize = (high-low) + 1;
  
      int mid = (high+low)/2;
      if(key==A[mid].getNum()) return mid;//found it, no further recursion needed
      else if(rangeSize==1) return -1;//not in array
  
  
      if (key&lt;A[mid].getNum()) return binarySearch(A, key, low, mid);
      else return binarySearch(A, key, mid+1, high);        
  }
  </code></pre>
  
  <p>Why is it still expecting an int when key is declared as a long?</p>