| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
About Exam
medium Solved by 19 students
Array Loop Boundary Error
< Prev
Next >

What is the primary logical error in the following modifyArray method?

public class ArrayModification {
    public static void modifyArray(int[] arr) {
        for (int i = 0; i <= arr.length; i++) {
            arr[i] *= 2;
        }
    }
}
A

The method does not return the modified array.

B

The multiplication operation might cause integer overflow.

C

The loop condition uses ‘<=’ instead of ‘<’, leading to an ArrayIndexOutOfBoundsException.

D

The array is modified without checking for null values.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1bommasam00033 1m 41s 199
#2upadhgau00011 0m 00s 100
#3hiboyshello11 0m 00s 100
#4kazvin.tjakradinata11 0m 04s 96
#5singhris00011 0m 07s 93
#6suhanakochhar00611 0m 36s 64
#7midnightasdark12 0m 56s 34
#8theofanusmischa11 1m 22s 18
#9sathilak00011 1m 57s -17
#10sailajavadlamani3313 6m 05s -285
Items per page:
10
1 – 10 of 12
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy