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 231–240 of 376
  1. 231
  2. 232
  3. 233
  4. 234
  5. 235
  6. 236
  7. 237
  8. 238
  9. 239
  10. 240

Question 231

Multiple choice Iteration
Consider the following code segment. int n = 50; int count = 0; while (n > 4) { if (n % 2 ==…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 232

Multiple choice Iteration
Consider the following code segment. int count = 0; for (int i = 0; i < 4; i++) { for (int j =…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 233

Multiple choice Iteration
Consider the following method. public static int mystery(int n) { int count = 0; while (n > 0) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 234

Multiple choice Iteration
Consider the following code segment. int total = 0; for (int i = 1; i <= 7; i++) { total…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 235

Multiple choice Iteration
Consider the following code segment. int sum = 0; for (int k = 2; k <= 9; k = k + 2) { if (k…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 236

Multiple choice Iteration
Consider the following code segment. int n = 18; int total = 0; while (n > 0) { total…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 237

Multiple choice Iteration
Consider the following code segment. int result = 1; for (int i = 0; i <…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 238

Multiple choice Iteration
Consider the following code segment. int total = 0; for (int i = 1; i <= 5; i++) { if (i % 2 ==…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 239

Multiple choice Iteration

Consider the following code segment.

int x = 4;
int y = 6;

if (x + y > 10)
{
    x = y - x;
}
else
{
    y = x + y;
}

if (x * 2 >= y)
{
    y = y - x;
}
else
{
    x = x + y;
}

System.out.println(x + " " + y);

What is printed?

Pick an answer, then check it. The solution opens in a window.

Question 240

Multiple choice Iteration
Consider the following code segment. String s = "banana"; int count = 0; while (s.indexOf("na") >=…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 231 of 376
Page 24 of 38