wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP Computer Science A Post Unit 2 Check

Total questions: 18

Worksheet time: 9mins

Name
Class
Date
1.

If x = 3 and y = 5, choose all the statements that evaluate to True.

a)

x < y

b)

y > -x**2

c)

2 * x == y

d)

y % x == 3

2.

A Boolean expression...

a)

Fixes any errors in the line of code

b)

Sets everything in it equal to each other

c)

Checks if something is true or false

d)

Loops the program to continue infinitely

3.

How many values does a Boolean variable have?

a)

4

b)

3

c)

2

d)

1

e)

Infinite

4.

a = 5

b = 6

Determine the truth value of the following statement:


((a <= b) or (a == b)) and (b > a)

a)

True

b)

False

5.

Which Java type can be used to store a true or false value?

a)

boolean

b)

bool

c)

Boolean

d)

Bool

6.
 Evaluate (to true or false) each of the following expressions:
14 >= 14
15 > 15
16 != 16
18 >= 19
a)
T, F, F, F
b)
T, T, T, T
c)
F, T, F, F
d)
F, T, T, F
7.

True/False: The body of an "if" statement will only be executed if the condition is true.

a)

True

b)

False

8.

What is the value of num after this statement is executed?


int num = 23;

if(num>20) { num = 20; }

else { num = 30; }

a)

20

b)

30

c)

23

d)

true

9.

What is missing from the command: System.___.println("Hello World");

a)

prt()

b)

Sys

c)

java

d)

out

10.

How many classes are required in a Java Program?

a)

At least one.

b)

None, you can run a basic program without a class.

c)

Two, one for the main function and one for the function code.

d)

None of the above.

11.

Which is the correct way to end a command statement in Java?

a)

;

b)

,

c)

.

d)

:

12.

Which of the reserved words is missing in this line which is found in every Java program?

public _____ void main(String[] args) {

a)

private

b)

void

c)

open

d)

static

13.

Which reserved word allows other classes to access your class in Java?

a)

private

b)

call

c)

public

d)

open

14.

Which of these is NOT a primitive datatype in Java?

a)

float

b)

int

c)

String

d)

char

15.

If you wanted to store the value 2.5 in a variable what datatype would you need to use?

a)

char

b)

float

c)

int

d)

boolean

16.

What will the output be?

a)

Nothing, there is an error

b)

OrangeBlack

c)

Orange

d)

Black

17.

Which boolean operator should replace the @ in this code?

a)

=

b)

<=

c)

==

d)

equal

18.

What is the value of bool after running this code?

a)

true

b)

undefined

c)

false

d)

5 + 7