I have the following simple Java statement:
public static void main(String[] args)
{
int[] grades = {102, 105, 98, 105};
Sorts.selectionSort(grades);
for (int grade : grades) {
// {
System.out.println(grade);
try {
System.out.print(grades[grade] + " ");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Error!");
}
}
And I'm getting the following output:
102
Error!
105
Error!
98
Error!
105
Error!
Why would the loop iterate to values that aren't in the array? I'm quite confused.
Thank you.