what will happen if a program uses an array index that is out of bounds in java code example
Example 1: java array out of bounds
//Use index inside the bounds of the array
Example 2: how to fix Index 2 out of bounds for length 2 when looping through an array in java
1
2
3
for (int i = 0; i < a.length; i++) { // GOOD
sum += a[i];
}