Verityprep
Question Bank · Unit 2

AP® Computer Science A Selection and Iteration Practice Questions

Work through AP Computer Science A practice 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 221–230 of 740
  1. 221
  2. 222
  3. 223
  4. 224
  5. 225
  6. 226
  7. 227
  8. 228
  9. 229
  10. 230

Question 221

Multiple choice Boolean Expressions
Consider the code segment if (n == 1) k++; else if (n == 4) k += 4; Suppose that the given segment is rewritten in the form if (/* condition */) /* assignment…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 222

Multiple choice Boolean Expressions
Consider the following code snippet: public class Main { public static void main(String[] args) { boolean a = true; boolean…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 223

Multiple choice Iteration
Consider the following code segment: int i = 2; for (int k = 0; k <= 12; k += i) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 224

Multiple choice Iteration
Consider the following code segment: int a = 1, b = 2; for (int k = 1; k <= 2; k++) { int oldA = a; a…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 225

Multiple choice Boolean Expressions
Assume that the int variables a and b have been properly declared and initialized. For which of the following pairs of values of a and b is the…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 226

Multiple choice Iteration
Consider the following code segment, which is supposed to calculate and print the sum of the numbers from 1 to 20: int count = 0,…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 227

Multiple choice Boolean Expressions
Assume that the boolean variables x, y, and z have been properly declared and initialized. Given that x is true, y is true, and…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 228

Multiple choice Iteration
Consider the following code segment. int n = 1, d = 1, s = 1; while (n <= 5) { System.out.print(s +…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 229

Multiple choice Boolean Expressions
Assume that the boolean variables a, b, and c have been properly declared and initialized. Which of…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 230

Multiple choice Iteration
Consider the following code segment: int num = 5; while (num >= 0) { num -=…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 221 of 740
Page 23 of 74