WorksheetsAP CSA Unit 4 Review
Total questions: 10
Worksheet time: 30mins
What's the result?
double val = 9 / 4;
System.out.print(val + " ");
System.out.print((int) val + " ");
System.out.print(val + " ");
2.0 2 2.0
2.25 2 2.25
2.25 2 2.0
2.0 2 2
boolean a = false || ((9 / 4) % 3 == 2);
Which of the following assigns the same value to b as the value stored in a?
boolean b = false || ((5 / 2) % 3 == 2);
boolean b = false && ((9 / 4) % 3 == 1);
boolean b = true && ((9 / 4) % 3 == 1);
boolean b = true || ((9 / 4) % 3 == 1);
Assume that a, b, and c are boolean variables. Which of the following expressions is equivalent to !a && !(b || c)?
!(a && b) || !c
!a && (!b || !c)
!(a || b) || !c
!a && !b && !c
What is the output of the following code?
System.out.println(Math.pow(3, 4));
7.0
64.0
81.0
12.0
What is the output?
int n = 12;
if (n % 3 == 0 && !(n % 4 == 0)) {
System.out.println("A");
} else if (n % 4 == 0) {
System.out.println("B");
} else {
System.out.println("C");
}
A
B
C
No output
What is the output of the following code?
double x = 7.8;
int i = (int) x;
System.out.println(i);
7
Compilation error
8
7.8
What is the output of the following code?
int x = -8;
int y = 3;
System.out.println(Math.abs(x) - Math.abs(y));
-11
-5
11
5
Which of the following is equivalent to:
!(x > 10 && y == 0)
x <= 10 && y != 0
x <= 10 || y != 0
x > 10 || y == 0
x < 10 && y == 0
What is the output of the following code?
int score = 85;
if (score >= 90) {
System.out.println("A");
} else if (score >= 80) {
System.out.println("B");
} else {
System.out.println("C");
}
A
B
C
No output
Consider the method which is intended to return the largest of three integers:
public static int largest(int x, int y, int z) {
if ((x > y) && (x > z)) {
return x;
}
else if ((y > x) && (y > z)) {
return y;
}
else {
return z;
}
}
Which of the following identifies the condition in which largest may not work as intended?
When z has the largest value
When y and z are both less than x
When x and y have equal values
When x and z have equal values
