AP Computer Science Exam Sample MC [100% pass]
AP Computer Science Exam Sample MC [100% pass] Consider the following code segment. for (int k = 0; k< 20; k= k+ 2){ if (k % 3== 1) { S(k+ " "); } } What is printed as a result of executing the code segment? a. 4 16 b. 4 10 16 c. 0 6 12 18 d. 1 4 7 10 13 16 19 e. 0 2 4 6 8 *Ans* b Consider the following code segment. List<String> animals = new ArrayList<String>(); ("dog"); ("cat"); ("snake"); (2, "lizard"); (1, "fish"); e(3); Sln(animals); What is printed as a result of executing the code segment? a. [dog, fish, cat] b. [dog, fish, lizard] c. [dog, lizard, fish] d. [fish, dog, cat] e. The code throws an ArrayIndexOutOfBoundsException exception. *Ans* a Consider the following method. public static void mystery(List<Integer> nums) { for (int k = 0; k < (); k++) { if ((k).intValue() == 0) { e(k); } } } Assume that a List<Integer> values initially contains the following Integer values. [0, 0, 4, 2, 5, 0, 3, 0] What will values contain as a result of executing mystery(values)? a. [0, 0, 4, 2, 5, 0, 3, 0] b. [4, 2, 5, 3] c. [0, 0, 0, 0, 4, 2, 5, 3] d. [0, 4, 2, 5, 3] e. The code throws an ArrayIndexOutOfBoundsException exception. *Ans*
Written for
- Institution
- Graduation in computer science
- Course
- Graduation in computer science
Document information
- Uploaded on
- April 5, 2024
- Number of pages
- 38
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
ap computer science exam sample mc 100 pass