title: Algorithm to find the largest integer in array
body: <p>I am trying to create a method which returns an int - the value of the largest integer in the sent array.
  The way I want this method to work, is to check the first <strong>and</strong> the last element of the array in a for-loop, and work their way to the middle. So i = first integer, k = last integer. When <code>i = 0, k = n-1</code> (indexes), when <code>i = 1, k = n-2</code> if you catch my drift. In every loop it needs to check <code>if a[i]&gt;a[k]</code>. Then they switch places. Then I know that the largest number is in the leading half of the array, and then I want it to check that half, so ultimately the largest int is at index 0.</p>
  
  <p>I tried like this:</p>
  
  <pre><code>public static int maxOfArray(int[] a)
  {
      int length = a.length;
  
      if(length&lt;1)
          throw new NoSuchElementException("Not at least one integer in array");
  
      while (length &gt; 1)
      {
          int k = length;
  
          for(int i = 0; i &lt; length/2; i++)
          {
              k--;
  
              if(a[i]&lt;a[k])
              {
                  int j = a[i];
                  a[i] = a[k];
                  a[k] = j;
              }
          }
          length /=2;
      }
      return a[0];
  }
  </code></pre>
  
  <p>..but I don't really get it.. I'm having a hard time "picturing" what's happening here.. But it's not always working.. (though sometimes).</p>
  
  <p><strong>EDIT</strong>
  Also: The array {6,15,2,5,8,14,10,16,11,17,13,7,1,18,3,4,9,12}; will spit out 17 as the largest number. I realize I have to fix the odd-length bug, but I would like to solve this even-length array first..</p>