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.

Subtopic: Iteration Clear filter

Questions 191–200 of 376
  1. 191
  2. 192
  3. 193
  4. 194
  5. 195
  6. 196
  7. 197
  8. 198
  9. 199
  10. 200

Question 191

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 192

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 193

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 194

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 195

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 196

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 197

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 198

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 199

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 200

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 191 of 376
Page 20 of 38