πŸ“š

Β >Β 

πŸ’»Β 

Β >Β 

⌚️

6.6 MC Answers and Review

6 min readβ€’december 30, 2022


AP Computer Science AΒ πŸ’»

130Β resources
See Units

Answers and Review for Multiple Choice Practice on Arrays
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-OClXuw28A51p.png?alt=media&token=5f004818-97bc-4f6e-be30-dc536d927b2d

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?

https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-MSvZTqMMblGj.png?alt=media&token=179869a6-734d-4105-a717-7b8b4420989a
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?Β 

https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-aycArZXpBzcy.png?alt=media&token=4da56772-84ef-4fbd-8acf-ebedaa3d939a
A. below
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-ohxIPCdTxVzT.png?alt=media&token=a3356091-cd01-47ed-9a4a-c6c8b3007fbb
B. below
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-XsFtZJ11NtHK.png?alt=media&token=ee3ed1db-271e-4617-9634-d3aa5857d68b
C. below
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-TRrClEcNPjed.png?alt=media&token=c7125826-de42-4781-b955-00dcf4ca60f2
D. below
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-aPyznByurJFN.png?alt=media&token=9abc080f-e3e3-4ef2-8500-2d45842c9fed
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 /?

https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-hcLlh8NY7goo.png?alt=media&token=75a1ac3d-ab47-4b0b-893f-ca792fe2acb0
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?

https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-MEhcrN9RgRxh.png?alt=media&token=d62c7112-b65e-49c7-a323-98e7a8c121e3
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?

https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-lRfFgsbvcRSW.png?alt=media&token=33a00394-cea8-441d-8d14-71a9ae62cd20
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)?

https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-QWOYBhH6TCOf.png?alt=media&token=c1b40c61-5964-42fc-b962-9d983f7205de
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

Fiveable
Fiveable
Home
Stay Connected

Β© 2023 Fiveable Inc. All rights reserved.


Β© 2023 Fiveable Inc. All rights reserved.