title: Java finding the midpoint between two integers
body: <p>I'm attempting to find the integer midpoint between two integers. For example mid(2,3) would be 2, not 2.5. I had the below which works fine, but i'd like to work with numbers from MIN_VALUE to MAX_VALUE, and doing so causes overflow so completely incorrect results.</p>
  
  <pre><code>public static int mid(int x, int y){
      int midpoint =  (x+y)/2;
      return midpoint;
  }
  </code></pre>
  
  <p>I've now got:</p>
  
  <pre><code>public static int mid(int x, int y){
      int low = Math.min(x, y);
      int high = Math.max(x, y);
      int midpoint =  (low + high) &gt;&gt;&gt; 1;
      return midpoint;
  }
  </code></pre>
  
  <p>This seems to work for values of x and y from 0 up to Integer.MAX_VALUE, however is incorrect if x is a negative number and i'm unsure why that is?</p>