6.6 MC Answers and Review

6 min readdecember 30, 2022

AP Computer Science A 💻

130 resources
See Units

Answers and Review for Multiple Choice Practice on Arrays

Image From Wikipedia.

⛔STOP!⛔ Before you look at the answers make sure you gave this practice quiz a try so you can assess your understanding of the concepts covered in unit #. Click here for the practice questions: AP Name Unit 5 Multiple Choice Questions.
Facts about the test: The AP Computer Science A exam has 40 multiple choice questions and you will be given 90 minutes to complete the section. That means it should take you around 34 minutes to complete 15 questions.

*The following questions were not written by CollegeBoard and although they cover information outlined in the AP Computer Science A Course and Exam Description the formatting on the exam may be different.

1. Given the code segment: int[] arr = {1, 2, 3, 4, 5}; which of the following would set the first two elements of array arr to 10, making the new value of array arr {10, 10, 3, 4, 5} ?

A. arr [0, 1] = 10
B. arr[1] = 10; arr [2] = 10;
C. arr = 10, 10, 3, 4, 5
D. arr[0] = 10; arr [1] = 10;
Answer: the indexes for arrays start at 0
📄 Study AP CSA, Unit 6.1: Array Creation and Access

2. Given the method (below), with the code segment (below) that appears in a method in the same class as transform.

/ missing code /

arr = transform(arr);

After running the code segment, the array should be {1, 0, 1, 0}. Which of the following can replace / missing code / so that it works as intended?

A. I and III
B. I and II
C. III only
D. I only
Answer: I and III
📄 Study AP CSA, Unit 6.1: Array Creation and Access

3. If you have a program that reads the lines of a text file into a sequential list of lines, which of the following is a good reason to implement the list with an ArrayList of String objects rather than an array of String objects?

A. The String methods are easier to use with an ArrayList than with an array.
B. The get and set methods of the ArrayList are more convenient than the [] notation for arrays.
C. The size method of ArrayList gives instant access to the length of the list.
D. If any text file is long, ArrayList will automatically be resized. The array, though, may go out of bounds.
Answer: using arrays here will avoid the possible problem of going out of bounds
📄 Study AP CSA, Unit 6.1: Array Creation and Access

4. Consider writing a program that produces statistics for long lists of numerical data. Which of the following is the best reason to implement each list with an array, rather than an ArrayList of Integer (or Double) objects?

A. Removal of elements from a list is easier to code for an array than for an ArrayList.
B. Insertion of new elements into a list is easier to code for an array than for an ArrayList.
C. An array of primitive data is more efficient to manipulate than an ArrayList of wrapper objects that contain numbers.
D. Accessing individual elements in the middle of a list is easier for an array than for an ArrayList.
Answer: definition of array of primitive data
📄 Study AP CSA, Unit 6.1: Array Creation and Access

5. Which of the following for loops will give the same output as the code segment? 

A. below
B. below
C. below
D. below
Answer: trace through the FOR loop to confirm
📄 Study AP CSA, Unit 6.3: Enhanced For Loop for Arrays

6. Consider the class: (below). A program that simulates a bingo card declares an array of BingoCard. The array has NUMPLAYERS elements, where each element represents the card of a different player. Here is a code segment that creates all the bingo cards in the game (below): Which of the following is a correct replacement for

/ declare array of BingoCard /?

A. BingoCard[] players = new BingoCard[NUMPLAYERS];
B. int[] BingoCard = new BingoCard[NUMPLAYERS];
C. BingoCard[] players = new int[NUMPLAYERS];
D. int[] players = new BingoCard[NUMPLAYERS];
Answer: BingoCard[] players = new BingoCard[NUMPLAYERS];
📄 Study AP CSA, Unit 6.1: Array Creation and Access

7. Which of the following best shows the contents of the array after the code runs?

A. {10, 20, 50, 90, 50}
B. {10, 20, 50, 90, 140}
C. {10, 30, 60, 100, 150}
D. {10, 20, 30, 70, 120}
Answer: the loop will run 3 times: the 10 & 20 values will remain untouched. arr[2] will change from 30 to 20+30=50; arr[3] will change from 40 to 50+40=90; arr[4] will change from 50 to 90+50=140
📄 Study AP CSA, Unit 6.1: Array Creation and Access

8. What is a data structure used to implement a list object, where elements in the list are of the same type

A. object
B. static
C. method
D. array
Answer: definition of an array
📄 Study AP CSA, Unit 6.1: Array Creation and Access

9. Can statements following an array's initialization reassign data to a new array of a specified length?

A. only for integer arrays
B. sometimes
C. no
D. yes
Answer: for example, after initialization: data = new double[40]; now has a fixed length of 40
📄 Study AP CSA, Unit 6.1: Array Creation and Access

10. When arrays are declared, what are the elements initialized for automatically (default values)?

A. primitives: 1, boolean: true, objects: null
B. primitives: 1, boolean: false, objects: null
C. primitives: 0, boolean: false, objects: null
D. primitives: 0, boolean: true, objects: null
Answer: initialized or default values of arrays
📄 Study AP CSA, Unit 6.1: Array Creation and Access

11. Fibonacci numbers form a pattern starting with 1, 1.... after this, each next number is the sum of the previous 2: 1, 1, 2, 3, 5, 8, and 13. the given code (below) is meant to fill the fibs array with the first ten Fibonacci numbers but is not working correctly. Which of the following best explains why the code isn't working correctly?

A. In the for loop header, the initial value of j should be 0.
B. In the for loop header, the initial value of j should be 2.
C. The for loop condition should be j < fibs.length - 1.
D. The for loop should increment j by 2 instead of by 1.
Answer: -memory for previous data is recycled
📄 Study AP CSA, Unit 6.3: Enhanced For Loop for Arrays

12. Which of the following is used for accessing the index of any element, removing / replacing elements, or when just want to access SOME of the elements

A. for loop
B. while loop
C. if loop
D. do while loop
Answer: definition/use of for loop with respect to array & elements of arrays
📄 Study AP CSA, Unit 6.3: Enhanced For Loop for Arrays

13. Which of the following will be the result of running the given code (below)?

A. A run-time error will result
B. an infinite loop will result
C. Sum of arr [1], arr[2],..., arr [arr.length-1] will be stored in sum
D. Sum of arr [0], arr[1],..., arr [arr.length] will be stored in sum
Answer: run-time error will result (ArrayIndexOutOfBoundsException)
📄 Study AP CSA, Unit 6.1: Array Creation and Access

14. How are primitive types passed?

A. by object
B. by method
C. by reference
D. by value
Answer: a copy is made of the actual parameter and the copy is erased once the method is exited
📄 Study AP CSA, Unit 6.2: Traversing Arrays

15. Which of the following is NOT an advantage of arraylists over arrays?

A. ArrayLists can shrink & grow while arrays have fixed lengths
B. an ArrayList's last slot is always list.size() while for a partially filled array you must keep track of the last slot
C. arrays can shrink & grow while ArrayLists have fixed lengths
D. in an ArrayList, System.out.print(list) outputs the element, while in an array you must write code to override toString() or else the output is a hashcode
Answer: facts/definition
📄 Study AP CSA, Unit 6.1: Array Creation and Access

What can we help you do now?

🔍 Study for Unit 7
🦘 Jump to AP CSA Unit 7 Multiple Choice Questions
🤝 Connect with other students studying AP CSA with Hours
Browse Study Guides By Unit
Unit 1 – Primitive Types
📱Unit 2 – Using Objects
🖥Unit 3 – Boolean Expressions & if Statements
🕹Unit 4 – Iteration
⚙️Unit 5 – Writing Classes
⌚️Unit 6 – Array
💾Unit 7 – ArrayList
💻Unit 8 – 2D Array
🖲Unit 9 – Inheritance
🖱Unit 10 – Recursion
🙏Exam Reviews

Stay Connected

© 2023 Fiveable Inc. All rights reserved.

© 2023 Fiveable Inc. All rights reserved.