AP CSP Practice Test On Arrays (ArrayList And 2D Arrays)

Access More Questions
Refer to the following code segment. You may assume that array arr1 contains elements arr1[0], arr1[1], . . . , arr1[N-1] , where N = arr1.length . int count = 0; for (int i = 0; i < N; i++) { if (arr1[i] != 0) { arr1[count] = arr1[i]; count++; } } int[] arr2 = new int[count]; for (int i = 0; i < count; i++) { arr2[i] = arr1[i]; } If array arr1 initially contains the elements 0, 6, 0, 4, 0, 0, 2 in this order, what will arr2 contain after execution of the code segment?
Correct Answer:
6, 4, 2
Explanation:
Correct answer: 6, 4, 2

Access more questions from this quiz

Continue to AP CSP Practice Test on Arrays (ArrayList and 2D arrays) for more practice questions and the full quiz experience.

Access More Questions