πŸ“š

Β >Β 

πŸ’»Β 

Β >Β 

⌚️

6.5 Multiple Choice Questions

5 min readβ€’june 18, 2024


AP Computer Science AΒ πŸ’»

130Β resources
See Units

Multiple Choice Practice for Arrays

Welcome to Unit 6 AP Computer Science A Multiple Choice Questions! Grab some paper and a pencil πŸ“„ to record your answers as you go. You can see how you did on the Unit 6 Practice Questions Answers and Review sheet once you're done. Don't worry, we have tons of resources available if you get stumped πŸ˜• on a question. And if solo study is not your thing, join a group in Hours!
Not ready to take a quiz yet? Start studying unit 6 Here: Intro to Unit 6
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-aMgXhoraCHj9.png?alt=media&token=7c24164b-880f-4e47-839c-ca7d2a4eb295

Image From Wikipedia.

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;

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-iIrZClg6velD.png?alt=media&token=df061e24-a658-4bda-83a4-525e5c160f5f
A. I and III
B. I and II
C. III only
D. I only

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.

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.

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-61G0EHYhmlvN.png?alt=media&token=5225df49-8db4-4003-9753-c5c648c927c6
A.
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-jWc43qw93UKN.png?alt=media&token=b09188dd-cd5d-4d87-9291-6461d40a5da0
B.
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-jEMoEWcLUZ77.png?alt=media&token=a73275cc-4f89-4101-bccf-0914d1d09401
C.
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-PamXXqSpmoXj.png?alt=media&token=27f37767-1de4-431e-a203-f995e5b34ffa
D.
https://firebasestorage.googleapis.com/v0/b/fiveable-92889.appspot.com/o/images%2F-gRVuNUOVhkUG.png?alt=media&token=43e0fbaf-b967-4bee-91a7-d1df2a6ea025

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-I5Q5mZgUXihd.png?alt=media&token=51e75d80-37e3-4bd4-99c5-0cb88269d81e
A. BingoCard[] players = new BingoCard[NUMPLAYERS];
B. int[] BingoCard = new BingoCard[NUMPLAYERS];
C. BingoCard[] players = new int[NUMPLAYERS];
D. int[] players = new BingoCard[NUMPLAYERS];

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-TMn0cbMINdvl.png?alt=media&token=bd6a3942-16d5-4cbf-af0e-3e12e596fb3c
A. {10, 20, 50, 90, 50}
B. {10, 20, 50, 90, 140}
C. {10, 30, 60, 100, 150}
D. {10, 20, 30, 70, 120}

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

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

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

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-cPWGPLGyMfqR.png?alt=media&token=b82a144d-9c84-428e-9d3f-773d63353ba3
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.

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

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-cLFKcUrMl3vG.png?alt=media&token=ff70878b-daae-4dda-85b8-4af8e50792ee
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

14. How are primitive types passed?
A. by object
B. by method
C. by reference
D. by value

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

Time to Check Your Answers onΒ Unit 6 Practice Questions Answers and Review! πŸ™Œ
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 7 – ArrayList
πŸ’»Unit 8 – 2D Array
πŸ–²Unit 9 – Inheritance
πŸ–±Unit 10 – Recursion
🧐Exam Skills