Verityprep
Question Bank · Unit 2

AP® Computer Science A Selection and Iteration Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions on Selection and Iteration, 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.

Questions 371–380 of 692
  1. 371
  2. 372
  3. 373
  4. 374
  5. 375
  6. 376
  7. 377
  8. 378
  9. 379
  10. 380

Question 371

Multiple choice Iteration
Consider the following code segment. int n = 1; int k = 0; while (n < 50) { n = n * 2; k =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 372

Multiple choice Boolean Expressions
Consider the following boolean expression, where a, b, and c are int variables. a > 0…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 373

Multiple choice Boolean Expressions
Consider the following method. public static String grade(int score) { String result = ""; if (score >= 90) { result = "A"; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 374

Multiple choice Iteration
Consider the following code segment. int[] arr = {1, 2, 3, 4, 5}; for (int i = 0; i < arr.length / 2; i++) { int temp = arr[i]; arr[i] =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 375

Multiple choice Iteration
Consider the following code segment.
ArrayList<Integer> nums = new ArrayList<Integer>();
nums.add(2);
nums.add(4);
nums.add(4);
nums.add(6);
nums.add(4);
for (int i = 0; i < nums.size(); i++)
{
    if (nums.get(i) == 4)
    {
        nums.remove(i);
    }
}
System.out.println(nums);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 376

Multiple choice Iteration
Consider the following method. public static int count(int n) { if (n < 1) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 377

Multiple choice Boolean Expressions
Consider the following class. public class Logger { private int calls; public Logger() { calls = 0; } public boolean ping() { calls = calls + 1; return true; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 378

Multiple choice Boolean Expressions
Consider the following method. public static String tier(int score) { if (score >= 90) { return "gold"; } else if (score >=…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 379

Multiple choice Iteration
Consider the following code segment. int sum = 0; for (int i = 5; i <= 20; i = i + 3) { if (i % 2…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 380

Multiple choice Boolean Expressions
Consider the boolean expression below, where a, b, and c are boolean variables.
!(a && (b || !c))
Which of the following is logically equivalent to the expression above?
Pick an answer, then check it. The solution opens in a window.
Question 371 of 692
Page 38 of 70