wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP CSA Unit 4 Review

Total questions: 10

Worksheet time: 30mins

Name
Class
Date
1.

What's the result?

double val = 9 / 4;

System.out.print(val + " ");

System.out.print((int) val + " ");

System.out.print(val + " ");

a)

2.0 2 2.0

b)

2.25 2 2.25

c)

2.25 2 2.0

d)

2.0 2 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?

a)

boolean b = false || ((5 / 2) % 3 == 2);

b)

boolean b = false && ((9 / 4) % 3 == 1);

c)

boolean b = true && ((9 / 4) % 3 == 1);

d)

boolean b = true || ((9 / 4) % 3 == 1);

3.

Assume that a, b, and c are boolean variables. Which of the following expressions is equivalent to !a && !(b || c)?

a)

!(a && b) || !c

b)

!a && (!b || !c)

c)

!(a || b) || !c

d)

!a && !b && !c

4.

What is the output of the following code?

System.out.println(Math.pow(3, 4));

a)

7.0

b)

64.0

c)

81.0

d)

12.0

5.

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)

A

b)

B

c)

C

d)

No output

6.

What is the output of the following code?

double x = 7.8;

int i = (int) x;

System.out.println(i);

a)

7

b)

Compilation error

c)

8

d)

7.8

7.

What is the output of the following code?

int x = -8;

int y = 3;

System.out.println(Math.abs(x) - Math.abs(y));

a)

-11

b)

-5

c)

11

d)

5

8.

Which of the following is equivalent to:

!(x > 10 && y == 0)

a)

x <= 10 && y != 0

b)

x <= 10 || y != 0

c)

x > 10 || y == 0

d)

x < 10 && y == 0

9.

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)

A

b)

B

c)

C

d)

No output

10.

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?

a)

When z has the largest value

b)

When y and z are both less than x

c)

When x and y have equal values

d)

When x and z have equal values