I have this method call from main:
exercise.SmallestOf(new int[] {2,9,6,4,8,34,2,15,81})
this is what the method does:
public int SmallestOf(int[] collection) {
int min = 0;
for(int i:collection) {
if (collection[i]<min)
min = collection[i];
}
return min;
}
I get a ArrayIndexOutOfBoundsException error at runtime. I assume there is something wrong with this:
new int[] {2,9,6,4,8,34,2,15,81}
I know I can do this:
int[] c = new int[] {2,9,6,4,8,34,2,15,81}
exercise.SmallestOf(c)
but I still want to know: what happens in the back that generates the error?