Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions on Data Collections, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Subtopic: Arrays Clear filter

Questions 271–280 of 300
  1. 271
  2. 272
  3. 273
  4. 274
  5. 275
  6. 276
  7. 277
  8. 278
  9. 279
  10. 280

Question 271

Multiple choice Arrays

What is printed?

int[] data = {3, 7, 2, 8, 5, 1, 9, 4, 6};
int maxDiff = 0;
for (int i = 0; i < data.length - 1; i++) {
    int diff = Math.abs(data[i] - data[i + 1]);
    if (diff > maxDiff) {
        maxDiff = diff;
    }
}
System.out.println(maxDiff);
Pick an answer, then check it. The solution opens in a window.

Question 272

Multiple choice Arrays

After one pass of this code, what is arr[arr.length - 1]?

int[] arr = {2, 5, 1, 8, 3};
for (int i = 0; i < arr.length - 1; i++) {
    if (arr[i] > arr[i + 1]) {
        int temp = arr[i];
        arr[i] = arr[i + 1];
        arr[i + 1] = temp;
    }
}
Pick an answer, then check it. The solution opens in a window.

Question 273

Multiple choice Arrays
int[] arr = {4, 7, 2};…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 274

Multiple choice Arrays
int[] arr = new int[3];…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 275

Multiple choice Arrays
int[] arr = null;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 276

Multiple choice Arrays
int[] arr = new int[3];…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 277

Multiple choice Arrays
Integer[] arr = new Integer[3];…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 278

Multiple choice Arrays
String[] arr = new String[3];…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 279

Multiple choice Arrays
String[] arr = null; if (arr == null) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 280

Multiple choice Arrays
public static int countNull(String[] arr) { int count = 0; for (int i = 0;i < arr.length;i++) { if (arr[i] == null) { count++; } } return count; } String[]…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 271 of 300
Page 28 of 30