AP Computer Science A Unit 6 Progress Check: MCQ Questions 2023
AP Computer Science A Unit 6 Progress Check: MCQ Questions 2023Consider the following code segment. int[] arr = {1, 2, 3, 4, 5}; Which of the following code segments would correctly set the first two elements of array arr to 10 so that the new value of array arr will be {10, 10, 3, 4, 5} ? - ANSWER A. arr[0] = 10; arr[1] = 10; Consider the following method. public int[] transform(int[] a) { a[0]++; a[2]++; return a; } The following code segment appears in a method in the same class as transform. /* missing code */ arr = transform(arr); After executing the code segment, the array arr should contain {1, 0, 1, 0}. Which of the following can be used to replace /* missing code */ so that the code segment works as intended? int[] arr = {0, 0, 0, 0}; int[] arr = new int[0]; int[] arr = new int[4]; - ANSWER E. I and III Consider the following method, which is intended to return the number of strings of length greater than or equal to 3 in an array of String objects. public static int checkString(String[] arr) { int count = 0; for (int k = 0; k < h; k++) { if (arr[k].length() >= 3) { count++; } } return count; } Which of the following code segments compile without error? checkString(new String[]); checkString(new String[0]); String[] str = {"cat", "dog"};checkString(str); - ANSWER D. II and III only Consider the following code segment. int[] arr = {10, 20, 30, 40, 50}; for(int x = 1; x < h - 1; x++) { arr[x + 1] = arr[x] + arr[x + 1]; } Which of the following represents the contents of arr after the code segment has been executed? - ANSWER C. {10, 20, 50, 90, 140} Consider the following code segment. int[] arr = {4, 3, 2, 1, 0}; int total = 0; for (int k = 0; k <= total; k++) { if (arr[k] % 2 == 0) { total += arr[k]; } else { total -= arr[k]; } }
Written for
- Institution
- Scie
- Course
- Scie
Document information
- Uploaded on
- April 24, 2023
- Number of pages
- 6
- Written in
- 2022/2023
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
ap computer science a unit 6 progress check mcq questions 2023
-
consider the following code segment int arr 1
-
2
-
3
-
4
-
5 which of the following code segments would correctly set the first two
Also available in package deal