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.

Subtopic: Boolean Expressions Clear filter

Questions 161–170 of 357
  1. 161
  2. 162
  3. 163
  4. 164
  5. 165
  6. 166
  7. 167
  8. 168
  9. 169
  10. 170

Question 161

Multiple choice Boolean Expressions
What is the result of executing the following code? int x = 0;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 162

Multiple choice Boolean Expressions
What is printed? int a = 5, b = 12; boolean p = !(a > 3 && b < 10); boolean…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 163

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 164

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 165

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 166

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 167

Multiple choice Boolean Expressions

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 168

Multiple choice Boolean Expressions

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 169

Multiple choice Boolean Expressions

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 170

Multiple choice Boolean Expressions
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 161 of 357
Page 17 of 36