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 331–340 of 692
  1. 331
  2. 332
  3. 333
  4. 334
  5. 335
  6. 336
  7. 337
  8. 338
  9. 339
  10. 340

Question 331

Multiple choice Iteration
What is printed?
int count = 0;
for (int i = 0; i < 5; i++)
{
    for (int j = i; j < 5; j++)
    {
        count++;
    }
}
System.out.println(count);
Pick an answer, then check it. The solution opens in a window.

Question 332

Multiple choice Boolean Expressions
Assume a, b, c, and d are properly declared int variables. Which of the following is always equivalent to the expression below?
!(a >= b) || (c == d)
Pick an answer, then check it. The solution opens in a window.

Question 333

Multiple choice Iteration
What is printed?
int sum = 0;
for (int k = 2; k <= 20; k += 3)
{
    sum += k;
}
System.out.println(sum);
Pick an answer, then check it. The solution opens in a window.

Question 334

Multiple choice Boolean Expressions
What is printed?
int a = 4;
int b = 0;
if (b != 0 && a / b > 1)
{
    System.out.print("X ");
}
if (a > 0 || (10 / b) > 0)
{
    System.out.print("Y");
}
Pick an answer, then check it. The solution opens in a window.

Question 335

Multiple choice Iteration
What is printed?
int n = 1;
int total = 0;
while (total < 30)
{
    total = total + n;
    n = n + 2;
}
System.out.println(n + " " + total);
Pick an answer, then check it. The solution opens in a window.

Question 336

Multiple choice Boolean Expressions
Assume x and y are boolean variables that have been properly initialized. Which of the following always evaluates to the same value as the expression below?
!x || y
Pick an answer, then check it. The solution opens in a window.

Question 337

Multiple choice Iteration
What is printed?
for (int i = 1; i <= 3; i++)
{
    for (int j = 1; j <= i; j++)
    {
        System.out.print(i + "" + j + " ");
    }
}
System.out.println();
Pick an answer, then check it. The solution opens in a window.

Question 338

Multiple choice Boolean Expressions
What is printed?
int a = 6, b = 9;
String msg = "";
if (a > 5 && b > 10)
{
    msg = "X";
} else if (a + b >= 15 || a == b)
{
    msg = "Y";
} else if (a > 0)
{
    msg = "Z";
}
System.out.println(msg);
Pick an answer, then check it. The solution opens in a window.

Question 339

Multiple choice Iteration
What is printed?
int count = 0;
for (int k = 1; k <= 50; k++)
{
    if (k % 3 == 0 && k % 5 != 0)
    {
        count++;
    }
}
System.out.println(count);
Pick an answer, then check it. The solution opens in a window.

Question 340

Multiple choice Boolean Expressions
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 331 of 692
Page 34 of 70