Verityprep
Question Bank · Unit 2

AP® Computer Science A Selection and Iteration Practice Questions

Work through AP Computer Science A practice 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 411–420 of 740
  1. 411
  2. 412
  3. 413
  4. 414
  5. 415
  6. 416
  7. 417
  8. 418
  9. 419
  10. 420

Question 411

Multiple choice Iteration
Consider the following code segment. int total = 0; for (int k = 1; k <= 20; k++) { if (k % 2 == 0 && k %…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 412

Multiple choice Iteration
Consider the following code segment.
int n = 128;
int steps = 0;
while (n > 1)
{
    n = n / 2;
    steps = steps + 1;
}
System.out.println(steps);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 413

Multiple choice Boolean Expressions
Consider the following boolean expression, where x is an int variable. (x > 0 && x < 10)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 414

Multiple choice Iteration
Consider the following code segment. int count = 0; for (int i = 1; i <= 4; i++) { for (int j = i; j…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 415

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 416

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 417

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 418

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 419

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 420

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 411 of 740
Page 42 of 74