6 min readβ’december 30, 2022
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} ?
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?
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?
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?
5. Which of the following for loops will give the same output as the code segment?Β
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 /?
7. Which of the following best shows the contents of the array after the code runs?
8. What is a data structure used to implement a list object, where elements in the list are of the same type
9. Can statements following an array's initialization reassign data to a new array of a specified length?
10. When arrays are declared, what are the elements initialized for automatically (default values)?
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?
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
13. Which of the following will be the result of running the given code (below)?
14. How are primitive types passed?
15. Which of the following is NOT an advantage of arraylists over arrays?
What can we help you do now?
Β© 2023 Fiveable Inc. All rights reserved.