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.

Questions 371–380 of 740
  1. 371
  2. 372
  3. 373
  4. 374
  5. 375
  6. 376
  7. 377
  8. 378
  9. 379
  10. 380

Question 371

Multiple choice Iteration
What is printed?
int n = 100;
int count = 0;
while (n > 1)
{
    n = n / 2;
    count++;
}
System.out.println(count);
Pick an answer, then check it. The solution opens in a window.

Question 372

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 373

Multiple choice Iteration
What is printed?
int count = 0;
for (int i = 0; i < 5; i++)
{
    for (int j = i; j < 5; j++)
    {
        count++;
    }
}
System.out.println(count);
Pick an answer, then check it. The solution opens in a window.

Question 374

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 375

Multiple choice Iteration
What is printed?
int sum = 0;
for (int k = 2; k <= 20; k += 3)
{
    sum += k;
}
System.out.println(sum);
Pick an answer, then check it. The solution opens in a window.

Question 376

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 377

Multiple choice Iteration
What is printed?
int n = 1;
int total = 0;
while (total < 30)
{
    total = total + n;
    n = n + 2;
}
System.out.println(n + " " + total);
Pick an answer, then check it. The solution opens in a window.

Question 378

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 379

Multiple choice Iteration
What is printed?
for (int i = 1; i <= 3; i++)
{
    for (int j = 1; j <= i; j++)
    {
        System.out.print(i + "" + j + " ");
    }
}
System.out.println();
Pick an answer, then check it. The solution opens in a window.

Question 380

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 371 of 740
Page 38 of 74