Verityprep
Question Bank

AP® Computer Science A Multiple Choice Questions

Work through AP Computer Science A multiple-choice 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 981–990 of 2,811
  1. 981
  2. 982
  3. 983
  4. 984
  5. 985
  6. 986
  7. 987
  8. 988
  9. 989
  10. 990

Question 981

Multiple choice Unit 2: Selection and Iteration

What is printed?

int a = 0, b = 5, c = 3;
boolean p = (a != 0) && (b / a > 1);
boolean q = (a == 0) || (b / a > 1);
boolean r = (c > b) || (a != 0) && (b > c);
System.out.println(p + " " + q + " " + r);
Pick an answer, then check it. The solution opens in a window.

Question 982

Multiple choice Unit 2: Selection and Iteration

What is printed?

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

Question 983

Multiple choice Unit 2: Selection and Iteration

What is printed?

int x = 12;
String label = "";
if (x % 2 == 0 && x % 3 == 0) {
    label = "A";
}
if (x % 4 == 0 && x % 3 == 0) {
    label = label + "B";
}
if (x % 6 == 0) {
    label = label + "C";
} else {
    label = label + "D";
}
System.out.println(label);
Pick an answer, then check it. The solution opens in a window.

Question 984

Multiple choice Unit 2: Selection and Iteration

What is printed?

String s = "MISSISSIPPI";
int count = 0;
int pos = s.indexOf("SS");
while (pos != -1) {
    count++;
    s = s.substring(pos + 2);
    pos = s.indexOf("SS");
}
System.out.println(count + " " + s.length());
Pick an answer, then check it. The solution opens in a window.

Question 985

Multiple choice Unit 2: Selection and Iteration

What is printed?

int a = 100, b = 73;
int count = 0;
while (a != b) {
    if (a > b) {
        a -= b;
    } else {
        b -= a;
    }
    count++;
}
System.out.println(a + " " + count);
Pick an answer, then check it. The solution opens in a window.

Question 986

Multiple choice Unit 2: Selection and Iteration

What is printed?

int score = 78;
String grade = "";
if (score >= 90) {
    grade = "A";
} else if (score >= 80) {
    grade = "B";
} else if (score >= 70) {
    grade = "C";
} else {
    grade = "F";
}
int bonus = score % 10;
if (bonus >= 5) {
    grade = grade + "+";
}
System.out.println(grade + " " + bonus);
Pick an answer, then check it. The solution opens in a window.

Question 987

Multiple choice Unit 2: Selection and Iteration

What is printed?

String s = "ABCDE";
String result = "";
for (int i = 0; i < s.length(); i++) {
    for (int j = 0; j <= i; j++) {
        result = result + s.substring(j, j + 1);
    }
}
System.out.println(result.length() + " " + result.substring(result.length() - 5));
Pick an answer, then check it. The solution opens in a window.

Question 988

Multiple choice Unit 2: Selection and Iteration
What is printed?

int x = 5, y = 10; boolean p = !(x > 3 && y < 15); boolean q = x <= 3 || y >= 15; boolean r = !(x > 3) || !(y < 15); System.out.println(p + " " + (p == q) + " " + (q == r));
Pick an answer, then check it. The solution opens in a window.

Question 989

Multiple choice Unit 2: Selection and Iteration

What is printed?

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

Question 990

Multiple choice Unit 2: Selection and Iteration

What is printed?

int total = 0;
for (int i = 1; i <= 100; i++) {
    if (i % 3 == 0 && i % 5 == 0) {
        total += i;
    }
}
System.out.println(total);
Pick an answer, then check it. The solution opens in a window.
Question 981 of 2,811
Page 99 of 282