Array Index Out Of Bounds Error
What error does the above code produce when executed?
public class ArrayMistake {
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
for (int i = 0; i <= numbers.length; i++) {
System.out.print(numbers[i] + " ");
}
}
}
A
ArrayIndexOutOfBoundsException
B
Compilation Error
C
NullPointerException
D
No error, prints all elements
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | upadhgau000 | 1 | 1 | 0m 00s | 100 |
| #2 | sathilak000 | 1 | 1 | 0m 05s | 95 |
| #3 | singhris000 | 1 | 1 | 0m 12s | 88 |
| #4 | bommasam000 | 2 | 2 | 1m 54s | 86 |
| #5 | y.seong2027 | 1 | 1 | 1m 25s | 15 |
| #6 | suhanakochhar006 | 0 | 2 | 1m 18s | -98 |
| #7 | geethasailaja | 2 | 7 | 11m 16s | -526 |
APFIVE