Verityprep
Question Bank

AP® Computer Science A Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions unit by unit, 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 1,031–1,040 of 2,811
  1. 1031
  2. 1032
  3. 1033
  4. 1034
  5. 1035
  6. 1036
  7. 1037
  8. 1038
  9. 1039
  10. 1040

Question 1031

Multiple choice Unit 2: Selection and Iteration
Consider the following code segment.
int x = 100;
int count = 0;
while (x > 1)
{
    if (x % 3 == 0)
    {
        x = x / 3;
    }
    else
    {
        x = x - 1;
    }
    count++;
}
System.out.println(count);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 1032

Multiple choice Unit 2: Selection and Iteration
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 1033

Multiple choice Unit 2: Selection and Iteration
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 1034

Multiple choice Unit 2: Selection and Iteration
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 1035

Multiple choice Unit 2: Selection and Iteration
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 1036

Multiple choice Unit 2: Selection and 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 1037

Multiple choice Unit 2: Selection and 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 1038

Multiple choice Unit 2: Selection and 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 1039

Multiple choice Unit 2: Selection and Iteration
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 1040

Multiple choice Unit 2: Selection and 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 1,031 of 2,811
Page 104 of 282