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 321–330 of 740
  1. 321
  2. 322
  3. 323
  4. 324
  5. 325
  6. 326
  7. 327
  8. 328
  9. 329
  10. 330

Question 321

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 322

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 323

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 324

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 325

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 326

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 327

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 328

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 329

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 330

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 321 of 740
Page 33 of 74