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 秒で採点します。

同じような問題をもっと解きたい?このトピックの新しい問題を、解きながら採点。

練習を始める