I didn't realize this would be the result if the call was operation(mat, 2, 1); or if the code segment in the for loop was result[j] = matrix[j][r] * matrix[c][j]; I mixed up that when accessing an element in a 2D array, the first index is the row and the second index is the column.
Question 19
I didn't realize that in condition III, the while loop will execute for x having the value 1, 3, 5, 7, and 9. So when x becomes 11 the loop will end. Even though the loop executes multiple times, the values assigned to x are not even, so nothing is printed.
Question 20
It returns the index, not m, I read it too fast.
Question 23
At the end of each pass, all original values will still be in the array, however, the order may be altered. So my answer did not make sense for the second line.
Question 28
I didn't think about how the / Assign to temp / expression is evaluated for every iteration of the outer loop. Therefore, the assignment is made 5 times.
Question 30
I oversaw that choice III will compute the incorrect price for numBoxes greater than or equal to 5 and will compute totalCost as numBoxes * 5.00 in all cases. This is because if numBoxes is greater than or equal to 5, it is also greater than 0 and the first if statement will evaluate to true and skip over the else statements.
Question 37
Because for choice II starts at the end of the array words and adds each word to result working right to left until it reaches the startIndex, the elements would be concatenated in reverse order.
Question 39
I read it wrong, this would the result if the first for loop used the get method instead of the set method.
Conclusion
I felt pretty out of practice reading code on a low level. I usually just read the code on a high level and just run it to see if it works, then using debugging techniques rather than looking at the low level too deeply. But, reading how code would compile and run is the biggest part of the ap exam so this is something I should focus on more in general.
Specifically one thing I had trouble with was the details of how inheritance syntax is in Java. I was able to get most of these questions right by narrowing down the other multiple choices by knowing they would not work. But I think it would be worthwhile both for the tests and myself to learn what causes errors with inheritance specially as that was my biggest struggle.
I was also really slow tracing nested loops which was not too big a problem but could be on a real exam.
ChatGPT conclusion
I also gave chatGPT my mistakes and asked it what the biggest problems are
Understanding 2D arrays: You seem to have mixed up the indices when accessing elements in a 2D array. Remember, the first index is for the row and the second index is for the column.
Loop conditions and execution: You missed how the while loop would execute for certain values of x. It’s important to trace the loop execution carefully.
Return values: You misread the return value of a function. Take time to understand what a function returns.
Array operations: You had a misunderstanding about the effect of certain operations on an array. Remember, the original values in an array remain after each pass, but the order may be altered.
Loop iterations: You overlooked how an expression is evaluated in every iteration of a loop. Keep in mind that expressions inside a loop are evaluated for each iteration.
Conditional statements: You missed how a series of if and else statements would execute. Remember, once a condition in an if statement is met, the subsequent else statements are skipped.
Order of concatenation: You didn’t realize that elements would be concatenated in reverse order when starting from the end of an array. The order of operations can significantly impact the result.
Method usage in loops: You misread the use of a method in a loop. Be sure to understand the effect of each method used in your code.
Corrections
Question 8
I didn't realize this would be the result if the call was operation(mat, 2, 1); or if the code segment in the for loop was result[j] = matrix[j][r] * matrix[c][j]; I mixed up that when accessing an element in a 2D array, the first index is the row and the second index is the column.
Question 19
I didn't realize that in condition III, the while loop will execute for x having the value 1, 3, 5, 7, and 9. So when x becomes 11 the loop will end. Even though the loop executes multiple times, the values assigned to x are not even, so nothing is printed.
Question 20
It returns the index, not m, I read it too fast.
Question 23
At the end of each pass, all original values will still be in the array, however, the order may be altered. So my answer did not make sense for the second line.
Question 28
I didn't think about how the / Assign to temp / expression is evaluated for every iteration of the outer loop. Therefore, the assignment is made 5 times.
Question 30
I oversaw that choice III will compute the incorrect price for numBoxes greater than or equal to 5 and will compute totalCost as numBoxes * 5.00 in all cases. This is because if numBoxes is greater than or equal to 5, it is also greater than 0 and the first if statement will evaluate to true and skip over the else statements.
Question 37
Because for choice II starts at the end of the array words and adds each word to result working right to left until it reaches the startIndex, the elements would be concatenated in reverse order.
Question 39
I read it wrong, this would the result if the first for loop used the get method instead of the set method.
Conclusion
I felt pretty out of practice reading code on a low level. I usually just read the code on a high level and just run it to see if it works, then using debugging techniques rather than looking at the low level too deeply. But, reading how code would compile and run is the biggest part of the ap exam so this is something I should focus on more in general.
Specifically one thing I had trouble with was the details of how inheritance syntax is in Java. I was able to get most of these questions right by narrowing down the other multiple choices by knowing they would not work. But I think it would be worthwhile both for the tests and myself to learn what causes errors with inheritance specially as that was my biggest struggle.
I was also really slow tracing nested loops which was not too big a problem but could be on a real exam.
ChatGPT conclusion
Understanding 2D arrays: You seem to have mixed up the indices when accessing elements in a 2D array. Remember, the first index is for the row and the second index is for the column.
Loop conditions and execution: You missed how the while loop would execute for certain values of x. It’s important to trace the loop execution carefully.
Return values: You misread the return value of a function. Take time to understand what a function returns.
Array operations: You had a misunderstanding about the effect of certain operations on an array. Remember, the original values in an array remain after each pass, but the order may be altered.
Loop iterations: You overlooked how an expression is evaluated in every iteration of a loop. Keep in mind that expressions inside a loop are evaluated for each iteration.
Conditional statements: You missed how a series of if and else statements would execute. Remember, once a condition in an if statement is met, the subsequent else statements are skipped.
Order of concatenation: You didn’t realize that elements would be concatenated in reverse order when starting from the end of an array. The order of operations can significantly impact the result.
Method usage in loops: You misread the use of a method in a loop. Be sure to understand the effect of each method used in your code.