why ArrayIndexOutOFBoundException in bidirectional bubble sort? : <p>I could not understand why this code is giving ArrayIndexOutOfBoundsException.
here is my code to implement bidirectional bubble sort.</p>

<pre><code>static void bubble(int[] a){
    int temp;
    for(int i=a.length-1,k=0;i!=k;i--,k++){
        for(int j=k;j&lt;i;j++){
            if(a[j]&gt;a[j+1]){
            temp=a[j];
            a[j]=a[j+1];
            a[j+1]=temp;
            }
        }
        for(int j=i-1;j&gt;k;j--){
            if(a[j-1]&gt;a[j]){
            temp=a[j];
            a[j]=a[j-1];
            a[j-1]=temp;
            }
        }
    }
}
</code></pre>
