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 181–190 of 357
  1. 181
  2. 182
  3. 183
  4. 184
  5. 185
  6. 186
  7. 187
  8. 188
  9. 189
  10. 190

Question 181

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 182

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 183

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 184

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 185

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 186

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 187

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 188

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 189

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 190

Multiple choice Boolean Expressions
Consider the following code segment.
int sum = 0;
for (int i = 1; i <= 10; i++)
{
    if (i % 3 == 0)
    {
        i++;
    }
    sum = sum + i;
}
System.out.println(sum);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.
Question 181 of 357
Page 19 of 36