2020 FRQ
Overall Score: 35/40 = 88%
Question 6
Consider the following expressions.
(double) 2 / 4 + 3
(double) (2 / 4) + 3
(double) (2 / 4 + 3)
I originally thought the second expression would also result in (double) casting as the division was applied, but division is before casting.
Question 26
Consider the following two code segments. Assume that the int variables m and n have been properly declared and initialized and are both greater than 0.
for (int i = 0; i < m * n; i++)
{
System.out.print("A");
}
for (int j = 1; j <= m; j++)
{
for (int k = 1; k < n; k++)
{
System.out.print("B");
}
}
Assume that the initial values of m and n are the same in code segment I as they are in code segment II. Which of the following correctly compares the number of times that ”A” and ”B” are printed when each code segment is executed?
I got this question incorrect because I originally thought that the conditional for the first for loop was j <= m.
Question 29
public static int calcMethod(int num)
{
if (num == 0)
{
return 10;
}
return num + calcMethod(num / 2);
}
What value is returned by the method call calcMethod(16) ?
I thought this was 31, because I thought the base case (num == 0) would return 0, not 10, so I forgot to factor in the 10.
Question 36
/** Precondition: a > 0 and b > 0 */
public static int methodOne(int a, int b)
{
int loopCount = 0;
for (int i = 0; i < a / b; i++)
{
loopCount++;
}
return loopCount;
}
/** Precondition: a > 0 and b > 0 */
public static int methodTwo(int a, int b)
{
int loopCount = 0;
int i = 0;
while (i < a)
{
loopCount++;
i += b;
}
return loopCount;
}
Which of the following best describes the conditions under which methodOne and methodTwo return the same value?
I chose a%b == 1, not a%b == 0 because I miscounted.
Question 40
public class A
{
public String message(int i)
{
return "A" + i;
}
}
public class B extends A
{
public String message(int i)
{
return "B" + i;
}
}