title: Weird ArrayIndexOutOfBoundsException
body: <p>I am getting a weird array index out of bound exception when I use the length of the array as the index</p>
  
  <p>I have twice checked everything and printed some stuff like the array.length to the console</p>
  
  <p>Here is the problematic code</p>
  
  <pre class="lang-java prettyprint-override"><code>public static boolean doJumpSearch(int array[], int number) {
  
             int start = 0;
             int end = (int) Math.sqrt(array.length); 
  
  
  
             while(array[end] &lt;= number &amp;&amp; end &lt; array.length) {
                start = end; 
                end += (int)Math.sqrt(array.length);
                if(end &gt; array.length - 1)
                   end = array.length; 
             }
  
             for(int i = start; i&lt;end; i++) { 
                if(array[i] == number)
                   return true; 
             }
             return false;
  
      } 
  </code></pre>
  
  <p>Here is the runner code</p>
  
  <pre class="lang-java prettyprint-override"><code>public static void main(String[] args) {
  
          int[] a = {1, 2, 3};
  
  
  
          if(search.doJumpSearch(a, 3)) System.out.println("Yup");
  
      }
  </code></pre>
  
  <p>Here is the error</p>
  
  <pre class="lang-css prettyprint-override"><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
      at Rector.array.search.doJumpSearch(search.java:46)
      at dummy.main(dummy.java:12)
  </code></pre>