I got "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6" error while i'm running this program.This code is to implement selection sort.please can someone help me.
package Sorting;
public class Selection {
public static void sort(int[] array) {
int min, temp;
for (int i = 0; i <= array.length-1 ; i++) {
min = i;
for (int j = i+1; j <= array.length ; j++) {
if ( array[j]<array[min]) {
min = j;
}
}
temp = array[min];
array[min]=array[i];
array[i] = temp;
}
}
public static void main(String[] args) {
int a[] = {51,6,3,55,34,12 };
sort(a);
for (int i :a) {
System.out.println(a[i]);
}
}
}