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 秒完成。

想多做幾條同類題目?立即開始練習呢個課題,即做即批改。

立即練習