Limited access

Upgrade to access all content for this subject

List Settings
Sort By
Difficulty Filters
Page NaN of 1946

Which of the following fragments of code will result in an ArrayIndexOutOfBoundsException error?

A
int count = 0;
int[] testScores = {78, 95, 82, 88, 100};
for(int i=0; i<testScores.length-1; i++)  
{
    if(testScores[i] > testScores[i+1])
        count++;
}
B
int count = 0;
int[] testScores = {78, 95, 82, 88, 100};
for(int i=testScores.length-1; i>0; i--)  
{
    if(testScores[i] > testScores[i-1])
    count++;
}
C
int count = 0;
int[] testScores = {78, 95, 82, 88, 100};
for(int i=0; i<testScores.length; i++)
{
    if(i != testScores.length-1 && 
        testScores[i] > testScores[i+1])
    count++;
}
D
int count = 0;
int[] testScores = {78, 95, 82, 88, 100};
for(int i=0; i>=testScores.length; i++)
{
    if(testScores[i]> testScores[i+1])
        count++;
}
E
int count = 0;
int[] testScores = {78, 95, 82, 88, 100};
for(int i=testScores.length-1; i>=0; i--)  
{
    if(testScores[i]> testScores[i+1])
        count++;
}
Accuracy 0%
Select an assignment template