Reading Java Like the Exam
- Terminology and concepts to look out for: output · condition · test
- Relevance to me: Many of the AP exam's multiple-choice questions ask you to read code and say what it does. Today you work one the way the exam asks it.
- Board Question: An AP question shows you eight lines of Java and asks what is printed. Name the first thing you would write on your scratch paper, and one mistake you would check for before you pick a choice.
Open the discussion form on the right and answer Section 1 from your first reading.
Answering a "What Is Printed?" Question
This section works through one exam-style Java question in three steps and then uses Code Coach to check the answer.
How the Exam Asks About Code
The AP Computer Science A Exam has a multiple-choice section of 42 questions, each with four choices. Several sample questions in the College Board's course description begin with the words "Consider the following code segment." The question shows a few lines of Java and then asks, "What is printed as a result of executing this code segment?", followed by four possible answers. The course description names five computational thinking practices and gives each one an approximate weighting for the multiple-choice section. Practice 3, Analyze Code, has the highest weighting of the five, so reading code is a large part of what that section asks. Part B of this course's final exam uses the same format. Figure 1 shows the worked item below laid out the way it appears on paper.
1int score = 17; 2int bonus = score % 5; 3if (score + bonus > 20) 4{ 5 System.out.println("high"); 6} 7else 8{ 9 System.out.println("low"); 10} 11System.out.println(score + bonus);
The item asks what is printed, and its four choices are (A) `high` then `19`, (B) `low` then `19`, (C) `low` then `17`, and (D) `high` then `22`. A student who reads the choices first can pick one that looks right without checking it, so the routine below starts with the code.
Tracing the Code in a Table
Step 1 is a trace table, drawn on scratch paper, with one column for each variable and one column for output, which is the layout the course description suggests for tracing code, plus a column for the line number. The student fills one row for each line that runs, in the order the lines run, and leaves out the lines that are skipped.
Line score bonus Output 1 17 2 17 2 3 17 2 9 17 2 low 11 17 2 19
Line 1 stores 17 in `score`, and line 2 stores 2 in `bonus`, because 17 divided by 5 is 3 with a remainder of 2, and the remainder operator keeps only the remainder. Storing the 2 is not output, because the 2 stays inside the program. Output is only what a print statement shows on the screen, so the Output column stays empty until a print statement runs.
Following the Condition and Checking Each Choice
Step 2 follows the path that the code takes, which depends on the condition on line 3, `score + bonus > 20`. The condition is the true-or-false expression in the parentheses after `if`. With the values in the table, the condition becomes 19 > 20, which is false. When the condition is false, the `else` block runs and the `if` block is skipped, so line 9 prints `low` and line 5 never runs. The print statements inside the braces are not the condition, because they are the code that the condition chooses between. The last line runs either way, because it sits after both blocks, so line 11 prints `19`.
Step 3 checks each choice against the table, starting with choices A and D, which print `high` and would need the condition to be true. Choice C prints 17, the value of `score` alone, which is the result of forgetting to add `bonus`. Choice D also adds 5, the number being divided by, instead of the remainder. Only choice B matches every row of the table, so B is the answer. Each wrong choice matches a real mistake, and checking all four choices can catch a mistake in the student's own table.
Code Coach as a Check After the Prediction
On the bench, Ask Code Coach opens only after a student checks an answer, so the student predicts first. A student who predicted B can then ask Code Coach what line 3 does. On October 19, 2026, that question was sent to Code Coach five times, with the code sent as numbered lines, the way the bench shows it. All five explanations were about line 3, the condition, and one of them said:
Line 3 checks if the sum of `score` and `bonus` is greater than 20. - `score` is 17 (from line 1). - `bonus` is `score % 5`, which is 17 % 5 = 2 (from line 2). So, it checks if 17 + 2 > 20, which is false.
This explanation agrees with the trace table, because a false condition sends the code to the `else` block. Code Coach's explanation is still not a test, because it is generated text and not the program's real output. Agreeing with a table-mate is not a test either, because neither student has compared the prediction with what the program actually printed. The test is running the real code, with the prediction as the expected output, and comparing the two. Real Java printed `low` and then `19`, which matches choice B and agrees with Code Coach's explanation. On the exam there is no Code Coach and no Run button, so the trace table is the test that a student can run on paper.
Summary
A "What is printed?" question is answered in three steps: trace the code in a table, follow the condition to the block that runs, and check every choice against the table. A stored value is not output until a print statement shows it. Code Coach explained line 3 correctly in all five saved runs, but only running the real code and comparing it with the prediction is a test.
Sources: College Board, AP Computer Science A Course and Exam Description (2025); Oracle, The if-then and if-then-else Statements (n.d.); Oracle, Assignment, Arithmetic, and Unary Operators (n.d.); Code Coach README and captures, mistral-small-2603 (2026); class site source code, coach.tsx (2026); course passages for Oct 26, Nov 3 and Nov 4 (2026).
-
notebook cue: output
In the worked item, `bonus` holds 2 after line 2. Is that 2 part of the output? Why or why not?
Check
No. The 2 is stored in `bonus` and stays inside the program, and output is only what a print statement shows on the screen. The 2 is never printed by itself; it only adds to the 19 that line 11 prints. See Tracing the Code in a Table, paragraph 2.
-
notebook cue: condition
What is the condition in the worked item's `if` statement, and is it true or false when `score` is 17?
Check
The condition is `score + bonus > 20`, the true-or-false expression in the parentheses after `if`. With `score` at 17 and `bonus` at 2, it becomes 19 > 20, which is false, so the `else` block runs and prints low. See Following the Condition and Checking Each Choice, paragraph 1.
-
notebook cue: test
You predicted choice B. What would count as a test of that prediction, and what would you compare?
Check
Running the real code counts as a test, with the prediction (low, then 19) as the expected output. You compare that prediction with what Java actually prints, which is low and then 19. Code Coach's explanation and a table-mate's agreement are not tests. See Code Coach as a Check After the Prediction, paragraph 2.
-
notebook cue: output
In the worked item, `bonus` holds 2 after line 2. Is that 2 part of the output? Why or why not?
Check
No. The 2 is stored in `bonus` and stays inside the program, and output is only what a print statement shows on the screen. The 2 is never printed by itself; it only adds to the 19 that line 11 prints. See Tracing the Code in a Table, paragraph 2.
-
notebook cue: condition
What is the condition in the worked item's `if` statement, and is it true or false when `score` is 17?
Check
The condition is `score + bonus > 20`, the true-or-false expression in the parentheses after `if`. With `score` at 17 and `bonus` at 2, it becomes 19 > 20, which is false, so the `else` block runs and prints low. See Following the Condition and Checking Each Choice, paragraph 1.
-
notebook cue: test
You predicted choice B. What would count as a test of that prediction, and what would you compare?
Check
Running the real code counts as a test, with the prediction (low, then 19) as the expected output. You compare that prediction with what Java actually prints, which is low and then 19. Code Coach's explanation and a table-mate's agreement are not tests. See Code Coach as a Check After the Prediction, paragraph 2.
Answering a "What Is Printed?" Question
This section works through one exam-style Java question in three steps and then uses Code Coach to check the answer.
How the Exam Asks About Code
The AP Computer Science A Exam has a multiple-choice section of 42 questions, each with four choices. Several sample questions in the College Board's course description begin with the words "Consider the following code segment." The question shows a few lines of Java and then asks, "What is printed as a result of executing this code segment?", followed by four possible answers. The course description names five computational thinking practices and gives each one an approximate weighting for the multiple-choice section. Practice 3, Analyze Code, has the highest weighting of the five, so reading code is a large part of what that section asks. Part B of this course's final exam uses the same format. Figure 1 shows the worked item below laid out the way it appears on paper.
1int score = 17; 2int bonus = score % 5; 3if (score + bonus > 20) 4{ 5 System.out.println("high"); 6} 7else 8{ 9 System.out.println("low"); 10} 11System.out.println(score + bonus);
The item asks what is printed, and its four choices are (A) `high` then `19`, (B) `low` then `19`, (C) `low` then `17`, and (D) `high` then `22`. A student who reads the choices first can pick one that looks right without checking it, so the routine below starts with the code.
Tracing the Code in a Table
Step 1 is a trace table, drawn on scratch paper, with one column for each variable and one column for output, which is the layout the course description suggests for tracing code, plus a column for the line number. The student fills one row for each line that runs, in the order the lines run, and leaves out the lines that are skipped.
Line score bonus Output 1 17 2 17 2 3 17 2 9 17 2 low 11 17 2 19
Line 1 stores 17 in `score`, and line 2 stores 2 in `bonus`, because 17 divided by 5 is 3 with a remainder of 2, and the remainder operator keeps only the remainder. Storing the 2 is not output, because the 2 stays inside the program. Output is only what a print statement shows on the screen, so the Output column stays empty until a print statement runs.
Following the Condition and Checking Each Choice
Step 2 follows the path that the code takes, which depends on the condition on line 3, `score + bonus > 20`. The condition is the true-or-false expression in the parentheses after `if`. With the values in the table, the condition becomes 19 > 20, which is false. When the condition is false, the `else` block runs and the `if` block is skipped, so line 9 prints `low` and line 5 never runs. The print statements inside the braces are not the condition, because they are the code that the condition chooses between. The last line runs either way, because it sits after both blocks, so line 11 prints `19`.
Step 3 checks each choice against the table, starting with choices A and D, which print `high` and would need the condition to be true. Choice C prints 17, the value of `score` alone, which is the result of forgetting to add `bonus`. Choice D also adds 5, the number being divided by, instead of the remainder. Only choice B matches every row of the table, so B is the answer. Each wrong choice matches a real mistake, and checking all four choices can catch a mistake in the student's own table.
Code Coach as a Check After the Prediction
On the bench, Ask Code Coach opens only after a student checks an answer, so the student predicts first. A student who predicted B can then ask Code Coach what line 3 does. On October 19, 2026, that question was sent to Code Coach five times, with the code sent as numbered lines, the way the bench shows it. All five explanations were about line 3, the condition, and one of them said:
Line 3 checks if the sum of `score` and `bonus` is greater than 20. - `score` is 17 (from line 1). - `bonus` is `score % 5`, which is 17 % 5 = 2 (from line 2). So, it checks if 17 + 2 > 20, which is false.
This explanation agrees with the trace table, because a false condition sends the code to the `else` block. Code Coach's explanation is still not a test, because it is generated text and not the program's real output. Agreeing with a table-mate is not a test either, because neither student has compared the prediction with what the program actually printed. The test is running the real code, with the prediction as the expected output, and comparing the two. Real Java printed `low` and then `19`, which matches choice B and agrees with Code Coach's explanation. On the exam there is no Code Coach and no Run button, so the trace table is the test that a student can run on paper.
Summary
A "What is printed?" question is answered in three steps: trace the code in a table, follow the condition to the block that runs, and check every choice against the table. A stored value is not output until a print statement shows it. Code Coach explained line 3 correctly in all five saved runs, but only running the real code and comparing it with the prediction is a test.
Sources: College Board, AP Computer Science A Course and Exam Description (2025); Oracle, The if-then and if-then-else Statements (n.d.); Oracle, Assignment, Arithmetic, and Unary Operators (n.d.); Code Coach README and captures, mistral-small-2603 (2026); class site source code, coach.tsx (2026); course passages for Oct 26, Nov 3 and Nov 4 (2026).
Each table agrees on a three-step routine for any "What is printed?" question, in order.
Chromebooks stay closed while your table talks. Sections 1 and 2 of the discussion form are already done. After you talk, finish Section 3 right here under My View. Submit before the exit ticket.
This form has three sections. Section 1: answer today's Board Question. Section 2: after the reading. Section 3 opens later in class. Today's Board Question: An AP question shows you eight lines of Java and asks what is printed. Name the first thing you would write on your scratch paper, and one mistake you would check for before you pick a choice.
CR 1. Board Question: An AP question shows you eight lines of Java and asks what is printed. Name the first thing you would write on your scratch paper, and one mistake you would check for before you pick a choice. Give your answer and one reason.
Write your answer in your lab notebook, labeled CR 1.
MC 1. Think about your answer to the board question. An AP question shows you eight lines of Java and asks what is printed. Name the first thing you would write on your scratch paper, and one mistake you would check for before you pick a choice. Which position is closest to yours now?
- Read the four choices first and pick the one that looks right.
- Trace the code line by line in a table, then match the output to a choice.
- Run the code in your head quickly and trust your first answer.
MC 2. (Reading claim 1) A value stored in a variable is printed automatically when the code ends.
- Agree
- Disagree
MC 3. (Reading claim 2) The condition in an `if` statement decides which block runs.
- Agree
- Disagree
MC 4. (Reading claim 3) Checking every choice against your trace can catch your own mistake.
- Agree
- Disagree
MC 5. (Reading claim 4) In the worked item, line 5 never runs, because the condition on line 3 is false.
- Agree
- Disagree
MC 6. (Reading claim 5) In Reading 2, `city.substring(4, 7)` returns four characters, because it includes the character at index 7.
- Agree
- Disagree
MC 7. (Reading claim 6) In Figure 1, choice C is crossed out because it prints 17, the value of `score` without `bonus`.
- Agree
- Disagree
MC 8. (Reading claim 7) In the five saved runs the passage describes, Code Coach explained line 2 when it was asked about line 3.
- Agree
- Disagree
MC 9. (Reading claim 8) In Reading 2, `city.indexOf(" ")` returns 3, because the space in "New Orleans" is at index 3.
- Agree
- Disagree
CR 2. (A different view) Write the view at your table that was most different from yours. If everyone agreed, write the strongest argument against your table's answer.
Write your answer in your lab notebook, labeled CR 2.
CR 3. Think about the Board Question again: An AP question shows you eight lines of Java and asks what is printed. Name the first thing you would write on your scratch paper, and one mistake you would check for before you pick a choice. Do you have the same opinion as when you first answered the board question? If it is the same, what from the reading or table talk reaffirmed your opinion? If it is different, what from the reading or table talk changed your opinion?
Write your answer in your lab notebook, labeled CR 3.