Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections Practice Questions

Work through AP Computer Science A practice questions on Data Collections, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Questions 1,181–1,190 of 1,222
  1. 1181
  2. 1182
  3. 1183
  4. 1184
  5. 1185
  6. 1186
  7. 1187
  8. 1188
  9. 1189
  10. 1190

Question 1181

Multiple choice Sorting and Searching
Suppose arr is declared and initialized as follows. int[] arr = {7, 3, 9, 2, 5}; After one pass of selection sort that…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1182

Multiple choice Sorting and Searching
Suppose arr is declared and initialized as follows. int[] arr = {8, 4, 6, 3, 7}; After the first three passes of insertion sort…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1183

Multiple choice Sorting and Searching
Suppose a standard binary search is used to locate 12 in the following sorted array.…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1184

Multiple choice Using Text Files
A text file contains the following integers, separated by spaces. 6 2 9 3 8 Assume sc is a properly constructed Scanner that reads the file. What is printed by…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1185

Multiple choice Using Text Files
Consider the following class. public class ScoreEntry { private String name; private int score; public ScoreEntry(String n, int s) { name = n; score = s; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1186

Multiple choice Arraylists
Consider the following code segment. ArrayList<String> words = new ArrayList<String>(); words.add("ant");…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1187

Free response Arraylists
Information about players in a school league is stored in Player objects. public class Player { private String name; private int points; private boolean active;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1188

Multiple choice Arrays
Consider the following code segment. int[] a = {2, 4, 6}; int[] b = a; b[1] = a[0] +…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1189

Multiple choice Arraylists
Consider the following code segment. ArrayList<Integer> nums = new ArrayList<Integer>(); nums.add(2); nums.add(4); nums.add(3); nums.add(5);…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 1190

Multiple choice 2D Arrays

Consider the following code segment.

int[][] grid = {
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9}
};

int sum = 0;

for (int r = 0; r < grid.length; r++)
{
    for (int c = 0; c < grid[0].length; c++)
    {
        if (r + c == 2)
        {
            sum = sum + grid[r][c];
        }
        else if (r == c)
        {
            sum = sum - grid[r][c];
        }
    }
}

What is the value of sum after the loops?

Pick an answer, then check it. The solution opens in a window.
Question 1,181 of 1,222
Page 119 of 123