Final Score: 42/52

Alt text

Time: 3 hours 48 minutes

Test Corrections

Question 1

Alt text

My Answer: 9

Reason why incorrect:

This would be the result if anArray was instantiated using new int[10][9] instead of new int[10][8].

Correct Answer: 8

Explanation:

In the first iteration of the outer loop, j has the value 0. The first 8 iterations of the inner loop access anArray[0][0] through anArray[0][7]. When an attempt is made to access anArray[0][8], an ArrayIndexOutOfBoundsException is thrown since anArray has 8 columns, numbered 0 through 7, inclusive.

Question 2

Alt text

My Answer: 2

Reason why incorrect:

This would be the result if the element immediately above mat[2][2] and the element immediately to its left had not been updated in an earlier iteration of the loop, so each still contained the value 1.

Correct Answer: 6

Explanation:

Every element of mat is modified, except those in the first row and the first column, which retain their initial values. Elements are traversed in row-major order. Each element of mat is replaced by the sum of the element immediately above it and the element to its left. In row 1, mat[1][1] is assigned the value mat[0][1] + mat[1][0] = 1 + 1 = 2, then mat[1][2] is assigned the value 1 + 2 = 3, and finally mat[1][3] is assigned the value 1 + 3 = 4. In row 2, mat[2][1] is assigned 2 + 1 = 3, and then mat[2][2] is assigned 3 + 3 = 6.

Question 7

Alt text

My Answer: 00101

Reason why incorrect:

This would be the result for the method call combine("10111", "01101"), for example.

Correct Answer: 00100

Explanation:

The combine method compares corresponding substrings of length 1 from input strings one and two. If the substrings are the same, the substring is appended to res; otherwise, "0" is appended to res. The first and second characters of res are "0" because the characters in position 0 and the characters in position 1 of one and two differ. The third character of res is "1" because the characters in position 2 of one and two are both "1". The fourth character in res is "0" because the characters in position 3 of one and two differ. The fifth character in res is "0" because the last characters of one and two are both "0". The value "00100" is returned.

Question 10

Alt text

My Answer: 008

Reason why incorrect:

This result would occur if the second line of code was replaced with str = str + 0 + 8;.

Correct Answer: 0008

Explanation:

The first line of code initializes the string str to "0". In the second line of code, the int values 0 and 8 are interpreted as strings. The second line of code concatenates str, "0", and "8" and then appends the result to str, setting str to "0008".

Question 18

Alt text

My Answer: Alt text

Reason why incorrect:

Since an enhanced for loop rather than a standard for loop is used, the value of num is an element in mat and not necessarily a valid column value of mat.

Correct Answer: Alt text

Explanation:

The algorithm uses nested enhanced for loops to iterate across all the elements in mat. The variable num is assigned the value of each element. If the positive difference between num and val is less than minDiff, num is the element of mat that is closest to val so far.

Question 23

Alt text

My Answer: Alt text

Reason why incorrect:

List is an interface, which an ArrayList implements. Please note that List is no longer tested as part of the AP CSA exam and ArrayList will be used instead. We want to avoid adding a comma at the end of the list of words not after the first element, so the boolean condition should be k != sizeOfList – 1.

Correct Answer: Alt text

Explanation:

List is an interface, which an ArrayList implements. Please note that List is no longer tested as part of the AP CSA exam and ArrayList will be used instead. To determine the size of an ArrayList we need to call the method size(). Each word will be separated by a comma, but no comma should appear after the last element in the list. Therefore, a comma is added as long as k does not equal the last index, sizeOfList – 1, since list indices start at 0.

Question 33

Alt text

My Answer: Alt text

Reason why incorrect:

The statement numbers[0].length returns the number of columns in numbers and numbers.length returns the number of rows. In this case, the outer loop will loop r from 0 to 3, not including 3. However, r is then used as the row index in printing numbers[r][c] and there are only two rows in numbers. An ArraylndexOutOfBoundsExeception will be thrown when the code attempts to access a third row that does not exist.

Correct Answer: Alt text

Explanation:

The outer for loop iterates over every row of numbers and assigns each row to the array row. The inner loop iterates over the array row accessing each element and assigning it to n. Then n is printed to the screen. In the first iteration of the outer loop, row is equal to {1, 2, 3}, and the inner loop will assign each successive value in row to n and print it to the screen, meaning 123 will be printed. For the second iteration of the outer loop, row is equal to {4, 5, 6}, and the inner loop will assign each successive value in row to n and print it to the screen, meaning 456 will be printed after 123, giving us the output 123456.

Question 42

Alt text

My Answer: [4, 2, 5, 3]

Reason why incorrect:

This would be the predicted result if List values initially contained [0, 4, 2, 5, 0, 3, 0]</p>

Correct Answer: [0, 4, 2, 5, 3]

Explanation:

nums.remove(k) is run when the value is 0. In turn, this decreases the index value of each number in the list. Because k constantly increase by one each time, whenever a 0 is removed, the following digit is not checked. This only becomes an issue when there are two consecutive zeroes in the list, which there are.

Question 43

Alt text

My Answer: "pilercom"

Reason why incorrect:

This would be the result if the first call to substring was word.substring(howFar, word.length()).

Correct Answer: "ilercom"

Explanation:

The two parameter substring method returns the substring beginning at the first parameter and ending at the second parameter – 1. When word is assigned “compiler” and howFar is assigned 3, the value of word.substring(howFar + 1, word.length()) is “iler”. This is the substring of “compiler” beginning at 3 + 1 or 4 and ending at 8 – 1 or 7. The value of word.substring(0, howFar) is “com”. This is the substring of “compiler” beginning at 0 and ending at 2. The method returns “ilercom”.

Question 52

Alt text

My Answer: Alt text

Reason why incorrect:

This image would require the second set of nested loops to initialize row to val – 1, increment both row and col in each iteration inner loop (instead of row being decremented) and changing the condition on the inner loop to col < 5 && row < 5.

Correct Answer: Alt text

Explanation:

The first set of nested for loops sets each element in board to “O”. The next for loop starts val at 0 and increments by 1 until val is 4, when val is 5 the loop terminates. When val is even, board is not updated, so nothing happens when val is 0. When val is 1, row is assigned 1 and col is assigned 0. The boolean condition in the while loop is true, so board[1][0] is assigned “X”. Then col is incremented to 1 and row is decremented to 0 and board[0][1] is assigned “X”. Then col is incremented to 2 and row is decremented to -1 and the while loop terminates. When val is 2, nothing changes about board. When val is 3, row is assigned 3 and col is assigned 0. The boolean condition in the while loop is true, so board[3][0] is assigned “X”. Then col is incremented to 1 and row is decremented to 2 and board[2][1] is assigned “X”. Then col is incremented to 2 and row is decremented to 1 and board[1][2] is assigned “X”. Then col is incremented to 3 and row is decremented to 0 and board[0][3] is assigned “X”. Finally, col is incremented to 4 and row is decremented to -1 and the while loop terminates. When val is 4, nothing changes about board.

</div> </div> </div>

Reflection

Skills I missed:

  • 1B: Determine code that would be used to complete code segments.
  • 2A: Apply the meaning of specific operators.
  • 2B: Determine the result or output based on statement execution order in a code segment without method calls (other than output).
  • 2C: Determine the result or output based on the statement execution order in a code segment containing method calls.
  • 2D: Determine the number of times a code segment will execute.

Overall, while I did do worse than the last College Board MC (66 Questions), I would say I learned more content while taking this test. For starters, I now understand what a for:each loops is, what it does, and how to use it. These loops come in handy and require little code, which is always more efficient. Something I need to work on is identifying when a variable is representing an actual value, or just the index number. This messed me up and confused me multiple times throughout the quiz, even on some questions I got correct. Lastly, I need to improve my skills when it comes to identifying errors in code. I am not very efficient in this skill, even when the issue is common (such as index decreasing, and code skipping over values). I did take longer than last quiz by about 30 minutes, and I was still over 2 hours more than the planned 1.5 hours, but I feel that my steady pace allowed me to really think about the trickier questions and understand new material.

</div>