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,021–1,030 of 2,811
  1. 1021
  2. 1022
  3. 1023
  4. 1024
  5. 1025
  6. 1026
  7. 1027
  8. 1028
  9. 1029
  10. 1030

Question 1021

Multiple choice Unit 2: Selection and Iteration
Consider the following code segment.
int[] a = { 2, 4, 6, 8 };
int i = 0;
while (i < a.length && a[i] % 2 == 0)
{
    i++;
}
System.out.println(i);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 1022

Multiple choice Unit 2: Selection and Iteration
Which of the following boolean expressions is equivalent to !(a > 5 && b <= 10) for all int values of a and b?
Pick an answer, then check it. The solution opens in a window.

Question 1023

Multiple choice Unit 2: Selection and Iteration
Consider the following code segment.
int x = 15;
int y = 20;
String r;
if (x > 10 && y < 15)
    r = "P";
else if (x > 10 || y > 15)
    r = "Q";
else if (x < 20 && y != 20)
    r = "R";
else
    r = "S";
What value is stored in r after the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 1024

Multiple choice Unit 2: Selection and Iteration
Consider the following code segment.
int count = 0;
for (int i = 1; i < 10; i++)
{
    for (int j = i; j < 10; j += 2)
    {
        count++;
    }
}
What value is stored in count after the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 1025

Multiple choice Unit 2: Selection and Iteration
Consider the following code segment.
for (int i = 0; i < 4; i++)
{
    for (int j = 0; j <= i; j++)
    {
        System.out.print("*");
    }
    System.out.println();
}
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 1026

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

Question 1027

Multiple choice Unit 2: Selection and Iteration
Consider the following code segment.
int n = 0;
int m = 1;
while (m < 1000)
{
    m = m * 2;
    n++;
}
System.out.println(n);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 1028

Multiple choice Unit 2: Selection and Iteration
Consider the following code segment.
int[] arr = { 3, 7, 2, 8, 5, 6 };
int target = 5;
boolean found = false;
int i = 0;
while (!found && i < arr.length)
{
    if (arr[i] == target)
    {
        found = true;
    }
    i++;
}
System.out.println(i);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 1029

Multiple choice Unit 2: Selection and Iteration
Which of the following boolean expressions is equivalent to !(x >= 10 || y == 0) for all int values of x and y?
Pick an answer, then check it. The solution opens in a window.

Question 1030

Multiple choice Unit 2: Selection and Iteration
Consider the following code segment.
int sum = 0;
for (int i = 1; i <= 10; i++)
{
    if (i % 3 == 0)
    {
        i++;
    }
    sum = sum + i;
}
System.out.println(sum);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.
Question 1,021 of 2,811
Page 103 of 282