Verityprep
Question Bank

AP® Computer Science A Practice Questions

Work through AP Computer Science A practice 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 3,091–3,100 of 3,140
  1. 3091
  2. 3092
  3. 3093
  4. 3094
  5. 3095
  6. 3096
  7. 3097
  8. 3098
  9. 3099
  10. 3100

Question 3091

Multiple choice Unit 4: Data Collections
Consider the following method.
public static int g(int n)
{
    if (n == 1)
        return 1;
    if (n % 2 == 0)
        return g(n / 2);
    return 1 + g(n - 1);
}
What value is returned by g(12) ?
Pick an answer, then check it. The solution opens in a window.

Question 3092

Multiple choice Unit 4: Data Collections
Consider the following code segment. int[] a = {7, 3, 9, 1, 5}; for (int i = 1; i < 4; i++) { int key = a[i]; int j = i - 1;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3093

Free response Unit 4: Data Collections

Information about applicants for a scholarship program is stored in Applicant objects.

public class Applicant
{
    private String name;
    private int score;
    private boolean complete;

    public Applicant(String n, int s, boolean c)
    {
        name = n;
        score = s;
        complete = c;
    }

    public String getName()
    {
        return name;
    }

    public int getScore()
    {
        return score;
    }

    public boolean isComplete()
    {
        return complete;
    }
}

The ScholarshipGroup class stores a list of applicants.

public class ScholarshipGroup
{
    private ArrayList<Applicant> applicants;

    public ScholarshipGroup(ArrayList<Applicant> list)
    {
        applicants = list;
    }

    public ArrayList<String> finalists(int minScore)
    { /* to be written */ }
}

Write the method finalists, which returns a new ArrayList<String> containing the names of all applicants who satisfy both of the following conditions.

  • The applicant's form is complete.
  • The applicant's score is at least minScore.

Among the applicants who satisfy those conditions, only applicants whose score is equal to the highest qualifying score should appear in the returned list. Names in the returned list must appear in the same order as the corresponding applicants appear in applicants. If no applicant qualifies, the method returns an empty list.

For example, if the qualifying applicants have scores 81, 94, 94, 88, the returned list should contain the names of the two applicants whose score is 94, in their original order.

The answer and the full solution open in a window.

Question 3094

Free response Unit 4: Data Collections
The TerrainMap class stores a rectangular grid of elevation values in meters. public class TerrainMap { private int[][] height; public TerrainMap(int[][] h) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3095

Multiple choice Unit 4: Data Collections
Consider the following code segment. int[] nums = {4, 1, 6, 3, 8}; int total = 0; for (int i = 0; i < nums.length - 1; i++) { if…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3096

Multiple choice Unit 4: Data Collections
Consider the following code segment.
ArrayList<Integer> values = new ArrayList<Integer>();
values.add(2);
values.add(5);
values.add(1);
values.add(5);

for (int i = values.size() - 1; i >= 0; i--)
{
    if (values.get(i) == 5)
        values.remove(i);
}

System.out.println(values);
What is printed?
Pick an answer, then check it. The solution opens in a window.

Question 3097

Multiple choice Unit 4: Data Collections
Consider the following code segment. int[][] m = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; int sum = 0; for (int r = 0; r < m.length;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3098

Multiple choice Unit 4: Data Collections
Consider the following method. public static int g(int n) { if (n ==…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 3099

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

Multiple choice Unit 4: Data Collections
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 3,091 of 3,140
Page 310 of 314