Verityprep
Question Bank

AP® Computer Science A Practice Questions

Work through AP Computer Science A practice questions unit by unit, 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 1,101–1,110 of 3,140
  1. 1101
  2. 1102
  3. 1103
  4. 1104
  5. 1105
  6. 1106
  7. 1107
  8. 1108
  9. 1109
  10. 1110

Question 1101

Multiple choice Unit 2: Selection and 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 1102

Multiple choice Unit 2: Selection and Iteration

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 1103

Multiple choice Unit 2: Selection and 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 1104

Multiple choice Unit 2: Selection and 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 1105

Multiple choice Unit 2: Selection and Iteration

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 1106

Multiple choice Unit 2: Selection and Iteration

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 1107

Multiple choice Unit 2: Selection and Iteration

What is printed?

int n = 2;
int count = 0;
while (n < 1000) {
    n = n * n;
    count++;
}
System.out.println(n + " " + count);
Pick an answer, then check it. The solution opens in a window.

Question 1108

Multiple choice Unit 2: Selection and Iteration

What is printed?

int n = 4821;
int reversed = 0;
while (n > 0) {
    reversed = reversed * 10 + n % 10;
    n = n / 10;
}
System.out.println(reversed);
Pick an answer, then check it. The solution opens in a window.

Question 1109

Multiple choice Unit 2: Selection and Iteration

What is printed?

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

Question 1110

Multiple choice Unit 2: Selection and Iteration

What is printed?

String s = "ABCDEFGHIJ";
String result = "";
for (int i = s.length() - 1; i >= 0; i--) {
    if (i % 3 == 0) {
        result += s.substring(i, i + 1);
    }
}
System.out.println(result);
Pick an answer, then check it. The solution opens in a window.
Question 1,101 of 3,140
Page 111 of 314