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 6. Click here for the practice questions:
AP Computer Science A Unit 6 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?
π€ Connect with other students studying AP CSA with
Hours