The following questions are similar to what you might see on the AP CSA exam. You may only take this test once while logged in. There are no time limits, but it will keep track of how much time you take. Click on the finish button after you have answered all the questions, and the number correct and feedback on the answers will be displayed.
We estimate that a score of about 50% on this test would correspond to the passing grade of 3 on the AP exam, a score of 65% to a 4, and a score of 80% and above to a 5 on the AP exam. These are just estimates and may not correspond to individual scores.
int max = 5;
//Loop I
for (int i = 0; i < max; i++)
{
System.out.print(i);
}
//Loop II
int j = 0;
while (j < max)
{
System.out.print(j);
j++;
}
//Loop III
int k = 0;
for (int i = max; i > 0; i--)
{
System.out.print(i);
}
I only
Loop I will produce this output, but it is not the only loop that will output these values.
II only
Loop II will produce this output, but it is not the only loop that will output these values.
II and III only
Loop II is correct, but loop III will produce the reverse output, 43210.
I and II only
Correct! Both of these loops will produce the correct output.
I, II, and III
While loop I and II will produce the correct output, loop III will actually produce the reverse of the correct output.
Use A and B to represent the expressions -- A becomes (x > 10), B becomes (x <= 5). ! (A && B) is NOT equivalent to (!A && !B).
(x > 10) && (x <=5)
Use A and B to represent the expressions -- A becomes (x > 10), B becomes (x <= 5). ! (A && B) is NOT equivalent to (A && B).
(x <= 10) && (x > 5)
Use A and B to represent the expressions -- A becomes (x > 10), B becomes (x <= 5). ! (A && B) is NOT equivalent to (!A && !B). The AND should be changed to an OR.
(x <= 10) || (x > 5)
Correct!
(x > 10) || (x <= 5)
Use A and B to represent the expressions -- A becomes (x > 10), B becomes (x <= 5). ! (A && B) is NOT equivalent to (A || B). Both A and B should also be negated.
public class Test1
{
public static void test(String str, int y)
{
str = str + "bow";
y = y * 2;
}
public static void main(String[] args)
{
String s = "rain";
int b = 4;
test(s, b);
System.out.println("s=" + s + "; b=" + b);
}
}
s="rainbow"; b=8;
Strings are immutable so changing str doesnβt affect the string that s refers to.
s="rain"; b=8;
Nothing done in the method test affects the value of b.
s="rainbow"; b=4;
Strings are immutable so changing str doesnβt affect the string that s refers to.
s="rain"; b=4;
Correct!
s="bow"; b=4;
All changes to string s result in a new string object.