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 341–350 of 692
  1. 341
  2. 342
  3. 343
  4. 344
  5. 345
  6. 346
  7. 347
  8. 348
  9. 349
  10. 350

Question 341

Multiple choice Boolean Expressions
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 342

Multiple choice Boolean Expressions
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 343

Multiple choice 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 344

Multiple choice 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 345

Multiple choice 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 346

Multiple choice 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 347

Multiple choice Boolean Expressions
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 348

Multiple choice Boolean Expressions
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 349

Multiple choice Boolean Expressions
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 350

Multiple choice 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 341 of 692
Page 35 of 70