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 281–290 of 692
  1. 281
  2. 282
  3. 283
  4. 284
  5. 285
  6. 286
  7. 287
  8. 288
  9. 289
  10. 290

Question 281

Multiple choice Iteration
What is printed? int sum = 0; for (int i = 1; i <= 3; i++) { for…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 282

Multiple choice Iteration
The following code generates a well-known sequence. What is printed? int a = 1, b = 1; for…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 283

Multiple choice Boolean Expressions
Consider this method that analyzes two-digit numbers. public static boolean…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 284

Multiple choice Iteration
What is printed? int x = 1; for (int i = 0; i <…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 285

Multiple choice Iteration

What is printed?

int product = 1;
for (int i = 1; i <= 6; i++) {
    if (i % 2 == 0) {
        product *= i;
    }
}
System.out.println(product);
Pick an answer, then check it. The solution opens in a window.

Question 286

Multiple choice Boolean Expressions

What is printed?

int a = 4, b = 7, c = 10;
boolean p = !(a < b && b < c);
boolean q = !(a < b) || !(b < c);
boolean r = a >= b || b >= c;
System.out.println(p + " " + q + " " + r + " " + (p == q && q == r));
Pick an answer, then check it. The solution opens in a window.

Question 287

Multiple choice Iteration

What is printed?

int sum = 0;
for (int i = 1; i <= 4; i++) {
    for (int j = i; j <= 4; j++) {
        sum += i * j;
    }
}
System.out.println(sum);
Pick an answer, then check it. The solution opens in a window.

Question 288

Multiple choice Iteration

What is printed?

String s = "aAbBcCdD";
String result = "";
for (int i = 0; i < s.length(); i++) {
    String ch = s.substring(i, i + 1);
    if (ch.compareTo("a") >= 0 && ch.compareTo("z") <= 0) {
        result += ch;
    }
}
System.out.println(result);
Pick an answer, then check it. The solution opens in a window.

Question 289

Multiple choice Boolean Expressions

What is printed?

int x = 6;
boolean a = x % 2 == 0 && x % 4 == 0;
boolean b = x % 3 == 0 || x % 4 == 0;
boolean c = !(x % 8 == 0) || (x % 2 == 0);
System.out.println(a + " " + b + " " + c);
Pick an answer, then check it. The solution opens in a window.

Question 290

Multiple choice Boolean Expressions

What is printed?

int a = 7, b = 3, c = 5;
int result = 0;
if (a > b + c) {
    result = 1;
} else if (a > b && a > c) {
    if (b + c > a + 1) {
        result = 2;
    } else {
        result = 3;
    }
} else {
    result = 4;
}
System.out.println(result);
Pick an answer, then check it. The solution opens in a window.
Question 281 of 692
Page 29 of 70