Verityprep
Question Bank

AP® Computer Science A Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions unit by unit, 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 2,801–2,810 of 2,811
  1. 2801
  2. 2802
  3. 2803
  4. 2804
  5. 2805
  6. 2806
  7. 2807
  8. 2808
  9. 2809
  10. 2810

Question 2801

Multiple choice Unit 4: Data Collections
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 2802

Multiple choice Unit 4: Data Collections
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 2803

Multiple choice Unit 4: Data Collections
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 2804

Multiple choice Unit 4: Data Collections

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 2805

Multiple choice Unit 4: Data Collections
Consider the following recursive method. public static int recur(int n) { if (n < 3) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2806

Multiple choice Unit 4: Data Collections
Selection sort is used on the array {6, 2, 8, 1,…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2807

Multiple choice Unit 4: Data Collections
Insertion sort is used on the array {9, 4, 7, 3, 8}. What is…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2808

Multiple choice Unit 4: Data Collections
A binary search is performed on the sorted array {2, 5, 9, 14, 20, 27, 31, 40} for target 27. The midpoint is computed…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2809

Multiple choice Unit 4: Data Collections
A text file "orders.txt" contains the following data. red 3 blue 5 green 2 Assume the file is opened successfully and the java.util.Scanner and java.io.File…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2810

Multiple choice Unit 4: Data Collections
A text file "scores.txt" contains the following lines. Ava,7,true Bo,9,false Cy,10,true Assume the file is opened successfully and the java.util.Scanner and…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 2,801 of 2,811
Page 281 of 282