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.

Subtopic: Boolean Expressions Clear filter

Questions 141–150 of 316
  1. 141
  2. 142
  3. 143
  4. 144
  5. 145
  6. 146
  7. 147
  8. 148
  9. 149
  10. 150

Question 141

Multiple choice Boolean Expressions
What is printed?
int x = 8;
boolean c1 = (x > 5 && x < 8);
boolean c2 = !(x >= 10) || x == 8;
boolean c3 = (x < 0 || x > 12) && x != 8;
System.out.println(c1 + " " + c2 + " " + c3);
Pick an answer, then check it. The solution opens in a window.

Question 142

Multiple choice Boolean Expressions
Assume a, b, c, and d are properly declared int variables. Which of the following is always equivalent to the expression below?
!(a >= b) || (c == d)
Pick an answer, then check it. The solution opens in a window.

Question 143

Multiple choice Boolean Expressions
What is printed?
int a = 4;
int b = 0;
if (b != 0 && a / b > 1)
{
    System.out.print("X ");
}
if (a > 0 || (10 / b) > 0)
{
    System.out.print("Y");
}
Pick an answer, then check it. The solution opens in a window.

Question 144

Multiple choice Boolean Expressions
Assume x and y are boolean variables that have been properly initialized. Which of the following always evaluates to the same value as the expression below?
!x || y
Pick an answer, then check it. The solution opens in a window.

Question 145

Multiple choice Boolean Expressions
What is printed?
int a = 6, b = 9;
String msg = "";
if (a > 5 && b > 10)
{
    msg = "X";
} else if (a + b >= 15 || a == b)
{
    msg = "Y";
} else if (a > 0)
{
    msg = "Z";
}
System.out.println(msg);
Pick an answer, then check it. The solution opens in a window.

Question 146

Multiple choice Boolean Expressions
Consider the following code segment.
int[] a = { 2, 4, 6, 8 };
int i = 0;
while (i < a.length && a[i] % 2 == 0)
{
    i++;
}
System.out.println(i);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 147

Multiple choice Boolean Expressions
Which of the following boolean expressions is equivalent to !(a > 5 && b <= 10) for all int values of a and b?
Pick an answer, then check it. The solution opens in a window.

Question 148

Multiple choice Boolean Expressions
Consider the following code segment.
int x = 15;
int y = 20;
String r;
if (x > 10 && y < 15)
    r = "P";
else if (x > 10 || y > 15)
    r = "Q";
else if (x < 20 && y != 20)
    r = "R";
else
    r = "S";
What value is stored in r after the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 149

Multiple choice Boolean Expressions
Consider the following code segment.
int[] arr = { 3, 7, 2, 8, 5, 6 };
int target = 5;
boolean found = false;
int i = 0;
while (!found && i < arr.length)
{
    if (arr[i] == target)
    {
        found = true;
    }
    i++;
}
System.out.println(i);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 150

Multiple choice Boolean Expressions
Which of the following boolean expressions is equivalent to !(x >= 10 || y == 0) for all int values of x and y?
Pick an answer, then check it. The solution opens in a window.
Question 141 of 316
Page 15 of 32