Tri 2 Test Corrections 2:
- Question 15
- Original Answer: A. Correct Answer: E.
- A is incorrect because in a string that has one or more occurrences of the letter “A,” the statement would discard the portion of str from the first occurence of “A” to the end. E is correct because the statement selects characters of str starting one character after pos.
- Question 25
- Original Answer: D. Correct Answer: B.
- D is incorrect because this would be the result if the loop condition was k > 1 instead of k > 0. B is correct the provided method contains a for loop with a loop control variable k, which starts at the last index of animals, decrements by 1 each iteration, until k is equal to 0.
- Question 35
- Original Answer: D. Correct Answer: C.
- D is incorrect because this would be the result if the print statement given printed the value at index k instead of the index itself. C is correct because it is the result when the print statement prints the correct index.
- Question 38
- Original Answer: C. Correct Answer: D.
- C is incorrect because this would be the result if the loop control variable in the for loop was str.length() instead of str.length() - 1. D is correct because when i is 4, temp is assigned l, when i is 3, p is appended to temp, when i is 2, p is appended to temp, and finally when i is 1, a is appended to temp, leading to a final result String of “lppa.”