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 401–410 of 740
  1. 401
  2. 402
  3. 403
  4. 404
  5. 405
  6. 406
  7. 407
  8. 408
  9. 409
  10. 410

Question 401

Multiple choice Iteration
Consider the following code segment. int n = 12; int step = 0; while (n > 1) { if (n % 2 == 0) n = n / 2;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 402

Multiple choice Boolean Expressions
Consider the following boolean expression, where x and y are int variables.
(x > 0 && y > 0) || (x > 0 && y <= 0)
Which of the following expressions is equivalent for all values of x and y?
Pick an answer, then check it. The solution opens in a window.

Question 403

Multiple choice Iteration
Consider the following code segment. int[] arr = { 2, 4, 6, 8, 10 }; int sum = 0; int i = 1; while (i <…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 404

Multiple choice Boolean Expressions
Consider the following code segment.
int age = 25;
if (age >= 18 && age < 65)
{
    System.out.print("adult ");
}
if (age < 18 || age >= 65)
{
    System.out.print("special ");
}
if (!(age >= 18) || !(age < 65))
{
    System.out.print("edge ");
}
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 405

Multiple choice Boolean Expressions
Consider the boolean expression below, where a, b, and c are int variables. !(a <= b)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 406

Multiple choice Iteration
Consider the following code segment. int x = 0; int y = 10; while (x < y) { x = x + 2; y =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 407

Multiple choice Iteration
Consider the following code segment, which is intended to remove every even value from nums. ArrayList<Integer> nums = new ArrayList<Integer>(); nums.add(2);…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 408

Multiple choice Boolean Expressions
Consider the following method.
public static String g(int n)
{
    if (n < 10)
    {
        return "" + n;
    }
    return (n % 10) + g(n / 10);
}
What is returned by the call g(1423)?
Pick an answer, then check it. The solution opens in a window.

Question 409

Multiple choice Boolean Expressions
Consider the following boolean expression, where a and b are int variables. !(a >= 10…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 410

Multiple choice Boolean Expressions
Consider the following method, which increments a counter and returns false. private int count = 0; public boolean check() { count++; return false; } Consider…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 401 of 740
Page 41 of 74