AP (Advanced Placement) · AP Computer Science A

Ethical and Social Issues Around Data Collection:练习题

5 道选择题即时批改,另有 2 道文字题附完整解题步骤,全部围绕「Ethical and Social Issues Around Data Collection」。

7 道题目17 免费,无需注册
第 1 题
1

A method findMax is intended to return the largest value in an array of integers.
public int findMax(int[] nums) {
  int max = nums[0];
  for (int i = 1; i < nums.length; i++) {
    if (nums[i] > max) {
      max = nums[i];
    }
  }
  return max;
}

Which of the following preconditions must be true for the method to work without throwing an exception?

第 2 题
1

Consider the following method that processes a 2D array:
public void process(int[][] mat) {
  for (int r = 0; r < mat.length; r++) {
    for (int c = 0; c < mat[0].length; c++) {
      if (r == c) {
        mat[r][c] *= 2;
      }
    }
  }
}

If mat is initialized as {{1, 2}, {3, 4}}, what is the value of mat after process(mat) is called?

第 3 题
1

Consider the following method designed to reverse the elements in an array:
public void reverse(int[] data) {
  for (int i = 0; i < data.length / 2; i++) {
    int temp = data[i];
    data[i] = data[data.length - 1 - i];
    data[data.length - 1 - i] = temp;
  }
}

If data is {1, 2, 3, 4, 5, 6}, how many total assignments to elements within data (lines involving data[...] = ...) are executed?

第 4 题
1

Consider the following code segment:
int[] arr = {1, 2, 3, 4, 5};
for (int i = 0; i < arr.length - 1; i++) {
  arr[i] = arr[i + 1];
}

What will be the contents of arr after the loop finishes execution?

第 5 题
1

Given a 2D array int[][] table = {{5, 10, 15}, {20, 25, 30}}, which expression correctly accesses the value 30?

第 6 题
5

Consider a scenario where you are managing a library system using a 1D array of Book objects named libraryShelf.
Part a: Write a code segment that iterates through the array and counts how many books have a price higher than \(P\), where \(P = 50.0\).
Part b: If the array is currently full with \(n\) elements, describe the steps and code logic required to 'remove' a book at index \(k\) while maintaining the relative order of the remaining books.
Part c: Calculate the minimum number of comparisons needed to find a specific book title in an unsorted array of size \(n = 100\) in the worst-case scenario.

先自己写一遍答案,再对照解题步骤。

第 7 题
7

A 2D array int[][] matrix of size \(M \times N\) represents a grayscale image where each value is an intensity between 0 and 255.
Part a: Write a nested loop structure to identify if the matrix is 'horizontally symmetric'. A matrix is horizontally symmetric if for every row \(i\) and column \(j\), matrix[i][j] == matrix[i][N - 1 - j].
Part b: Write a method applyThreshold(int limit) that modifies the 2D array: any value greater than limit becomes 255, and any value less than or equal to limit becomes 0.
Part c: Analyze the time complexity of the symmetry check in terms of \(M\) and \(N\). If \(M = 1000\) and \(N = 1000\), how many total comparisons are performed in the worst case?

先自己写一遍答案,再对照解题步骤。

* thinka 提供的内容由 AI 生成,未必在任何情况下都完全准确或最新,请结合官方教材与教师指导使用。

你已看过标准答案。现在轮到你的答案被批改。

这一页能告诉你好答案是什么样子,却无法指出你的答案缺了什么。thinka 按真实评分标准批改你的文字答案,约 15 秒完成。

想多做几道同类题目?立即开始练习这个课题,边做边批改。

立即练习