Page 592 - AP Computer Science A, 7th edition
P. 592
(A) The only odd int in nums is at position j.
(B) All values in positions 0 through j–1 are odd.
(C) All values in positions 0 through j–1 are even.
(D) All values in positions nums.length–1 down to j+1 are odd. (E) All values in positions nums.length–1 down to j+1 are
ev en.
14. Consider the following method.
public int mystery (int n) {
if (n == 0) return 0;
else if (n % 2 == 1) return n;
else
return n + mystery(n – 1);
}
What will be returned by a call to mystery(6)?
(A) 6 (B) 11 (C) 12 (D) 27 (E) 30
15. Consider the following code segment.
int num1 = value1, num2 = value2, num3 = value3; while (num1 > num2 || num1 > num3)
{
/∗ body of loop ∗ /
}
You may assume that value1, value2, and value3 are int values. Which of the following is sufficient to guarantee that /∗ body of loop ∗ / will never be executed?