AP CSA Unit 1 & 2 Review

Assessment
•
James Huval
•
Computers
•
9th - 12th Grade
•
311 plays
•
Hard
Student preview

10 questions
Show answers
1.
Multiple Choice
Consider the following code segment.
System.out.println("W");
System.out.println("X");
System.out.print("Y");
System.out.print("Z");
What is printed as a result of executing the code segment?
WXYZ
W
XYZ
WX
YZ
W
X
YZ
W
X
Y
Z
2.
Multiple Choice
Consider the following code segment.
int x = 10;
int y = 20;
/* missing code */
System.out.print(top / bottom);
Which of the following replacements for /* missing code */ will cause an ArithmeticException to occur?
I. int top = x - y;int bottom = y - x;
II.int top = 2 * x;int bottom = y - top;
III. int top = x + y;int bottom = 2 * top;
I. only
II. only
III. only
I. and II.
II. and III.
3.
Multiple Choice
Consider the following code segment.
String str = "AP";
str += "CS " + 1 + 2;
System.out.println(str);
What is printed as a result of executing the code segment?
CS AP12
AP CS3
CSAP 12
APCS 12
APCS 3
4.
Multiple Choice
Consider the following code segment.
String one = "ABC123";
String two = "C";
String three = "3";
System.out.println(one.indexOf(two));
System.out.println(one.indexOf(three));
System.out.println(two.indexOf(one));
What is printed when the code segment is executed?
2
5
-1
2
5
2
2
6
-1
3
6
-1
-1
-1
2
5.
Multiple Choice
Consider the following method.
public double calculate(double x)
{
return x + 1.5;
}
The following code segment calls the method calculate in the same class.
Double d1 = new Double(7.5);
System.out.println(calculate(d1));
What, if anything, is printed when the code segment is executed?
8.0
8.5
9
9.0
Nothing is printed because the code does not compile. The actual parameter d1 passed to calculate is a Double, but the formal parameter x is a double.
Explore all questions with a free account
Find a similar activity
Create activity tailored to your needs using
AP Computer Science A Year Review

•
9th - 12th Grade
Code.org APCSA Unit

•
9th - 12th Grade
AP CSA Unit 1 Review

•
10th Grade - University
AP CS Unit 1 Study Quiz

•
9th - 12th Grade
Csa unit 6

•
9th Grade
AP CSA Unit 3

•
10th - 12th Grade
AP CSA Review Unit 2

•
9th - 12th Grade
AP CSA Classes

•
9th - 12th Grade