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 21–30 of 376
  1. 21
  2. 22
  3. 23
  4. 24
  5. 25
  6. 26
  7. 27
  8. 28
  9. 29
  10. 30

Question 21

Multiple choice Iteration
Consider the following code segment. for (int k = 1; k <= 100; k++) if ((k % 4) == 0)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 22

Multiple choice Iteration
Consider the following code segment. int sum = 0; int k = 1; while (sum < 12 || k < 4) sum…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 23

Multiple choice Iteration
Consider the following code segment. int num = 2574; int result = 0; while (num > 0) { result = result * 10 +…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 24

Multiple choice Iteration
Consider the following code segment. int x = 1; while ( /* missing code */ ) { System.out.print(x + " "); x = x + 2; } Consider the following possible…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 25

Multiple choice Iteration
Why do we use…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 26

Multiple choice Iteration
What will this while loop do?…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 27

Multiple choice Iteration
Why does the following code produce an infinite loop? Choose the best answer. public…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 28

Multiple choice Iteration
Which statement could be added to the while loop below so that it doesn't run indefinitely?…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 29

Multiple choice Iteration
What does the following code print? int x = -4;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 30

Multiple choice Iteration
How many times will the following code print out the value of x? public static…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 21 of 376
Page 3 of 38