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 151–160 of 316
  1. 151
  2. 152
  3. 153
  4. 154
  5. 155
  6. 156
  7. 157
  8. 158
  9. 159
  10. 160

Question 151

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 152

Multiple choice Boolean Expressions
Consider the following code segment.
int c = 0;
for (int i = 0; i < 5; i++)
{
    for (int j = 0; j < 5; j++)
    {
        if (i + j < 5)
        {
            c++;
        }
    }
}
System.out.println(c);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 153

Multiple choice Boolean Expressions
Consider the boolean expression (a > b || b > c) && !(a > c). Which of the following sets of values for a, b, and c causes the expression to evaluate to true?
Pick an answer, then check it. The solution opens in a window.

Question 154

Multiple choice Boolean Expressions
Consider the boolean expression below, where x and y are int variables. !(x > 0 &&…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 155

Multiple choice Boolean Expressions
Consider the following method and code segment. public static int inc(int[] a) { a[0] = a[0] + 1; return a[0]; } int[] a = { 0 }; if (a[0] > 0 || inc(a) > 0) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 156

Multiple choice Boolean Expressions
Consider the following boolean expression, where x and y are int variables.
(x > 0 && y > 0) || (x > 0 && y <= 0)
Which of the following expressions is equivalent for all values of x and y?
Pick an answer, then check it. The solution opens in a window.

Question 157

Multiple choice Boolean Expressions
Consider the following code segment.
int age = 25;
if (age >= 18 && age < 65)
{
    System.out.print("adult ");
}
if (age < 18 || age >= 65)
{
    System.out.print("special ");
}
if (!(age >= 18) || !(age < 65))
{
    System.out.print("edge ");
}
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 158

Multiple choice Boolean Expressions
Consider the boolean expression below, where a, b, and c are int variables. !(a <= b)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 159

Multiple choice Boolean Expressions
Consider the following method.
public static String g(int n)
{
    if (n < 10)
    {
        return "" + n;
    }
    return (n % 10) + g(n / 10);
}
What is returned by the call g(1423)?
Pick an answer, then check it. The solution opens in a window.

Question 160

Multiple choice Boolean Expressions
Consider the following boolean expression, where a and b are int variables. !(a >= 10…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 151 of 316
Page 16 of 32