Skip to main content

AP Computer Science A MCQs

Pep mascot

Content Filters

Question Types

Tools

Export assessment:print

Not sure where to begin?

  • Recommended study guides
  • Answer 5 questions to see which guides will help you the most

Practice Settings

AP Computer Science A practice questions by unit

Fiveable has 5,505 AP Computer Science A multiple-choice practice questions across 4 units, plus 3 stimulus-based question sets built around a source. Practice one unit or topic at a time.

  • Unit 1 – Using Objects and Methods: 1,826 multiple-choice questions
  • Unit 2 – Selection and Iteration: 1,179 multiple-choice questions, 2 stimulus sets
  • Unit 3 – Class Creation: 803 multiple-choice questions
  • Unit 4 – Data Collections: 1,697 multiple-choice questions, 1 stimulus set

Sample AP Computer Science A practice question

Source:

Fiveable fictional Java practice code aligned to the AP Computer Science A Fall 2025 CED

Consider the following Java code.

</>Java
public class CountDown {
    public static int compute(int n) {
        int total = 0;
        int k = n;
        while (k > 0) {
            total += k;
            k -= 2;
        }
        return total;
    }

    public static void main(String[] args) {
        int result = compute(7);
        System.out.println(result);

        int x = 0;
        int limit = 4;
        while (x < limit) {
            System.out.print(x + " ");
            x++;
        }
    }
}

What is printed to the console as a result of executing the main method in the code shown?

16 0 1 2 3

Correct answer

16 0 1 2 3 4

12 0 1 2 3

16 1 2 3 4

Explanation

Tracing compute(7): iteration 1 k=7, total=7, k becomes 5; iteration 2 k=5, total=12, k becomes 3; iteration 3 k=3, total=15, k becomes 1; iteration 4 k=1, total=16, k becomes -1; condition -1>0 is false, loop exits, returns 16. println(16) prints '16' then newline. Second loop: x starts at 0, limit=4. Prints '0 ', '1 ', '2 ', '3 ', then x=4 fails x<4, loop ends. Full output is '16' on line 1 and '0 1 2 3 ' on line 2.

More AP Computer Science A practice