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 351–360 of 692
  1. 351
  2. 352
  3. 353
  4. 354
  5. 355
  6. 356
  7. 357
  8. 358
  9. 359
  10. 360

Question 351

Multiple choice Boolean Expressions
Consider the following code segment.
int c = 0;
for (int i = 0; i < 5; i++)
{
    for (int j = 0; j < 5; j++)
    {
        if (i + j < 5)
        {
            c++;
        }
    }
}
System.out.println(c);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 352

Multiple choice Boolean Expressions
Consider the boolean expression (a > b || b > c) && !(a > c). Which of the following sets of values for a, b, and c causes the expression to evaluate to true?
Pick an answer, then check it. The solution opens in a window.

Question 353

Multiple choice Boolean Expressions
Consider the boolean expression below, where x and y are int variables. !(x > 0 &&…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 354

Multiple choice Boolean Expressions
Consider the following method and code segment. public static int inc(int[] a) { a[0] = a[0] + 1; return a[0]; } int[] a = { 0 }; if (a[0] > 0 || inc(a) > 0) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 355

Multiple choice Iteration
Consider the following code segment. int k = 0; for (int i = 1; i <= 10; i++) { if (i % 3 == 0…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 356

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

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 357

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 358

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 359

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 360

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 351 of 692
Page 36 of 70