image

Question 2

image

Answer D is incorrect. This would be the result if the outer loop started at 1 and continued as long as r <= 3 was true, increasing r by 1 after each iteration, and if the inner loops were written with the second inner loop being before the first inner loop. Answer A is correct. The outer for loop iterates three times with r being assigned the values 3, 2, and 1. The two inner loops iterates a different number of times for each iteration of the outer loop depending on the value of r. During the first iteration of the outer loop, when r is 3, the first inner loop iterates two times for when c is equal to 1 and 2. This results in -- being printed. The second inner loop iterates one time for when c equals 3. This results in * being printed. Then the cursor moves to the next line and that concludes the first iteration of the outer loop. This pattern then continues.

Question 5

image

Answer C is incorrect. The value of (x && y) is true only when x is true and y is true, however, the value of (x || y) && x could be true if x is true and y is false. Therefore, these statements are not equivalent. Answer A is correct. For the expression to evaluate to true, the expressions on either side of the && operator must be true. If x is true then x || y is true regardless of the value of y, meaning (x || y) && x evaluates to true. If x is false, the expression evaluates to false regardless of the value of (x || y).

Question 7

image

Answer A is incorrect. This would be the result if the outer loop counter variable, outer, was incremented by 2 for each iteration. Answer C is correct. The outer loop iterates six times for when outer is assigned the values 1 through 6. For each iteration, the number of times the inner loop iterates is dependent on the value of outer.

Question 8

image

Correct answer would be B. In the first iteration of the for loop, j is 0. The value of result[0] is assigned the product of row 1, column 0, which is 1 and row 0, column 2, which is 1. Therefore, result[0] is assigned the value 1. The second iteration of the for loop, when j is 1, result[1] is assigned the product of row 1, column 1, which is 2, and row 1, column 2, which is 3. Therefore, result[1] is assigned the value 6. The third iteration of the for loop, when j is 2, result[2] is assigned the product of row 1, column 2, which is 3, and row 2, column 2, which is 1. Therefore, result[2] is assigned the value 3. The final iteration of the for loop, when j is 3, result[3] is assigned the product of row 1, column 3, which is 4, and row 3, column 2, which is 1. Therefore, result[3] is assigned the value 4.

Question 31

image
image

This was a misunderstanding error. Answer E is correct. 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.

Question 34

image

Answer D is correct. 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 39

image

Answer C is the correct option. The first for loop uses the set method to change the value of each element in students to “Alex”. When the set method is called, it returns the value that was originally at this index. So, the first loop will print Alex Bob Carl. At this point all elements have been set to “Alex”. The second for loop uses an enhanced for loop to access every element and will print Alex Alex Alex.