Atlasलॉग इन
Black FridayHalf off Premium, through Sunday, Nov 29.See plans
Practice exam

AP Computer Science A practice exam

The whole exam in its real format, timed, with free response graded on the rubric and a predicted 1–5 score. Try 5 real questions below first.

Take the full practice exam →Try 5 questions

Your first full exam is free with an account. Premium has no limit, and every exam is new.

What the AP Computer Science A exam looks like

2 sections, 3 h in all. The Atlas practice exam keeps the same sections, question counts, timing and weights, calculator and no-calculator parts included.

खंडप्रश्नसमयभार
Multiple choice (no calculator)421 h 30 min55%
Free response (no calculator)41 h 30 min45%

The free-response questions: Methods and control structures, Class design, Data analysis with ArrayList, 2D array.

Units on the exam

UnitShare of the exam
Using objects and methods15%–25%
Selection and iteration25%–35%
Class creation10%–18%
Data collections30%–40%

Weights from the College Board’s course and exam description. Each linked unit has its own practice test with sample questions.

5 free AP Computer Science A practice questions

Real questions from the Atlas exam pool, with the answer and the working.

  1. Consider the following code segment.

    String s = "notebook";
    int p = s.indexOf("b");
    String t = s.substring(p + 1) + s.substring(0, p);
    System.out.println(t);

    What is printed as a result of executing the code segment?

    1. Abooknote
    2. Booknote
    3. Cnoteook
    4. Dooknoteb
    Show the answer

    B.

    indexOf returns 4, the index of the first "b". s.substring(5) is "ook" (to the end) and s.substring(0, 4) is "note" (indexes 0 to 3), so t is "ooknote".

    booknote: keeps the "b": substring(p + 1) starts one past index p. noteook: joins the two pieces in the wrong order: the part after the letter comes first. ooknoteb: moves the "b" to the end: substring(0, p) stops before index p.

    ऑब्जेक्ट और मेथड का उपयोग

  2. Consider the following code segment.

    int n = 52816;
    int sum = 0;
    while (n > 0)
    {
      sum += n % 10;
      n /= 100;
    }
    System.out.println(sum);

    What is printed as a result of executing the code segment?

    1. A14
    2. B19
    3. C20
    4. D22
    Show the answer

    B.

    Each pass adds the ones digit, then n /= 100 drops the last two digits (int division). So the loop adds every other digit starting from the ones place: 6 + 8 + 5 = 19.

    14: stops one pass early: n is 5 (not 0) before the last pass, so 5 is added. 22: adds every digit, as n /= 10 would: n /= 100 drops two digits each pass. 20: adds the tens digit as well on the first pass.

    चयन और पुनरावृत्ति

  3. Consider the following class.

    public class Tank
    {
      private int level;
      private int capacity;
    
      public Tank(int cap)
      {
        capacity = cap;
        level = 0;
      }
    
      /** Adds amt units; returns the number of units that did not fit */
      public int fill(int amt)
      {
        int room = capacity - level;
        if (amt > room)
        {
          level = capacity;
          return amt - room;
        }
        level += amt;
        return 0;
      }
    
      public int getLevel()
      {
        return level;
      }
    }

    Consider the following code segment.

    Tank t = new Tank(10);
    int spill = t.fill(6);
    spill += t.fill(7);
    System.out.println(t.getLevel() + " " + spill);

    What is printed as a result of executing the code segment?

    1. A13 0
    2. B10 7
    3. C10 4
    4. D10 3
    Show the answer

    D.

    fill(6): room is 10, so the level becomes 6 and 0 is returned. fill(7): room is 4, so the level becomes 10 and 3 is returned. Printed: 10 3.

    13 0: never caps the level: when amt is more than room, level is set to capacity. 10 7: counts the whole amount that overflows as spilled: only amt - room does not fit. 10 4: returns the room that was left instead of the overflow.

    क्लास निर्माण

  4. Consider the following code segment.

    int[] a = {4, 9, 2, 7};
    for (int i = 1; i < a.length; i++)
    {
      a[i] = a[i - 1];
    }
    for (int v : a)
    {
      System.out.print(v + " ");
    }

    What is printed as a result of executing the code segment?

    1. A4 4 9 2
    2. B9 2 7 7
    3. C4 4 4 4
    4. D4 9 2 7
    Show the answer

    C.

    a[1] gets a[0], which is 4; then a[2] gets the new a[1], also 4, and so on. Going forward, 4 is copied into every element.

    4 4 9 2: shifts right by one: going forward, each element copies a value that was already overwritten. 9 2 7 7: copies from the right neighbor: the code copies a[i - 1]. 4 9 2 7: leaves the array unchanged: each assignment stores into a[i].

    डेटा कलेक्शन

  5. Consider the following code segment.

    int a = 7;
    int b = 2;
    double x = a / b;
    double y = (double) a / b;
    System.out.println(x + y);

    What is printed as a result of executing the code segment?

    1. A6.0
    2. B6.5
    3. C7.0
    4. D7.5
    Show the answer

    B.

    a / b divides two ints, giving 3, which is stored as 3.0. In (double) a / b the cast converts a first, so the division is done in doubles: 3.5. The sum is 6.5.

    6.0: truncates both: the cast applies to a before the division, so y keeps the fraction. 7.0: keeps the fraction in x: a / b is int division, done before the result is stored in a double. 7.5: rounds a / b up to 4: int division truncates.

    ऑब्जेक्ट और मेथड का उपयोग

Take the full AP Computer Science A exam →

Questions people ask

Is this AP Computer Science A practice exam free?
Yes, with a free Atlas account: your first full practice exam is free, free response graded too. The sample questions on this page need no account. Atlas Premium gives unlimited practice exams, and every exam is new, drawn from a pool of checked questions.
How long is the AP Computer Science A exam?
3 h in all: multiple choice, 42 questions in 1 h 30 min (55% of the score); free response in 1 h 30 min (45% of the score). The Atlas practice exam keeps the same sections, timing and weights.
How is the practice exam scored?
Multiple choice is marked right or wrong, free response is graded part by part against a rubric, and the sections are weighted as on the real exam to predict a grade from 1 to 5. On Atlas's scale a 5 takes about 72% of the points, a 4 about 58% and a 3 about 44%; the College Board sets the real boundaries each year.
Can I practice one unit at a time?
Yes. Each course has unit tests (up to 15 multiple-choice questions from one unit, timed at the exam's pace), and you can take the multiple choice or the free response on its own.

More: every practice exam · the Computer Science chapters · how Atlas compares