Array Loop with Out of Bounds Error
Consider the following Java code segment, where arr is an int array that has been properly initialized.
for (int i = 0; i <= arr.length; i++) {
if (arr[i] < arr[arr.length - i - 1]) {
System.out.println("ASCEND");
}
}
What is the maximum number of times that "ASCEND" can be printed by the execution of this code?
A
The code will cause a runtime error
B
arr.length / 2
C
arr.length
D
arr.length + 1
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE