Array Index Out Of Bounds Error
What is the result when the following code segment is 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 | namansoin000 | 1 | 1 | 0m 56s | 44 |
| #6 | midnightasdark | 1 | 3 | 0m 43s | 37 |
| #7 | y.seong2027 | 1 | 1 | 1m 25s | 15 |
| #8 | asda | 0 | 1 | 0m 01s | -11 |
| #9 | suhanakochhar006 | 0 | 2 | 1m 18s | -98 |
| #10 | geethasailaja | 2 | 7 | 11m 16s | -526 |
Items per page:
10
1 – 10 of 10
APFIVE