Hey lads. Doing a while loop question but am having a little difficulty with this question. I thought i knew enough to get questions like this correct but unfortunately not experienced enough. The following code is attempting to get sum of values in array that are less than 10. When i run program, it gives me an array out of bounds answer. Any ideas?
class q1 {
public static void main(String[] args){
int a[] = {1,3,14,6,12,2,14,5,8}; // declare array
int i = a.length;
int sum = 1;
while(a[i] < 10){ //while value in array is less than 10
sum *= a[i]; // sum of 1 is multiplied with values less than 10
i++; // go up through values in array
}
System.out.println(sum); // print out answer
}
}