title: Java, Bubble Sort, Arrays, Exception in thread "main" Error
body: <p>I have a tutorial in class today with bubble sort and I've got an error I don't know how to fix.</p>
  
  <p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
      at BubbleSorter.main(BubbleSorter.java:24)</p>
  
  <p>It is not assessed but I would like to get through it to continue on.
  Thank you. Below is my entire code.</p>
  
  <pre><code>public class BubbleSorter {
      public static void main(String[] args)
      {
          int i;
          int array[] = { 12, 9, 4, 99, 120, 1, 3, 10 };
          System.out.println("Array Values before the sort:\n");
          for (i = 0; i &lt; array.length; i++)
              System.out.print(array[i] + " ");
          System.out.println();
          System.out.println();
  
          bubble_srt(array, array.length);
  
          System.out.print("Array Values after the sort:\n");
          for (i = 0; i &lt; array.length; i++)
              ;
          System.out.print(array[i] + " ");
          System.out.println();
          System.out.println("PAUSE");
      }
  
      private static void bubble_srt(int[] array, int length) {
          int i, j, t = 0;
          for (i = 0; i &lt; length; i++) {
              for (j = 1; j &lt; (length - 1); j++) {
                  if (array[j - 1] &gt; array[j]) {
                      t = array[j - 1];
                      array[j - 1] = array[j];
                      array[j] = t;
                  }
              }
          }
      }
  }
  </code></pre>