Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

AP CSA Unit 3

Total questions: 34

Worksheet time: 1hrs 15mins

Name
Class
Date
1.

What does short circuit evaluation mean in the following code?

i) if (a < b && c != d)

a)

if a < b is false it evaluates c != d

b)

if a < b is false it doesn't evaluate c != d

c)

if c != d is false it evaluates a < b

d)

f c != d is false it doesn't evaluate a < b

e)

if a < b is true it doesn't evaluate c != d

2.

Which if statement below tests if the variable letter holds the char value #?

a)

if (letter == #)

b)

if (letter == "#")

c)

if (letter == '#')

d)

if (letter >= '#')

e)

if (letter = '#')

3.

What is 0 0 1 1 1 0 0 0 in base ten?

a)

54

b)

55

c)

56

d)

57

e)

58

4.

What is 67 in binary?

a)

0 1 0 0 0 0 1 0

b)

0 1 0 0 0 0 1 1

c)

0 1 0 0 0 1 1 0

d)

0 1 0 0 0 1 1 1

e)

0 1 0 0 1 1 1 0

5.

Consider the following code:

String w = "Rapunzel";

for (int i = 0; i < w.length(); i++) {

System.out.print(w.charAt(i) + " ");

if (i%4 == 3)

System.out.println();

}

What is output?

a)

R a p u

n z e l

b)

R a p

n z e l

c)

R a p u n z e l

d)

u l

e)

R a p n z e

6.

What does the String method substring() do?

a)

Returns a portion of the String.

b)

Tests two String objects for equality.

c)

Compares this String with a second String for greater than, equal to, or less than.

d)

Returns the character at a certain location as a char value.

e)

Returns the length of a String.

7.

What does the following code do?

String w3 = "aardvark";

System.out.println(w3.charAt(w3.length() – 2));

a)

Prints the second letter in the String.

b)

Prints the second to last letter in the String.

c)

Prints the last letter in the String.

d)

Prints the first letter in the String.

e)

Causes an index out of bounds error.

8.

Consider the following code:

String major = "Computer Science";

What is returned by the method call major.charAt(2)?

a)

'C'

b)

'o'

c)

'm'

d)

"C"

e)

"Science"

9.

What is the result of 3/2 in Java?

a)

1.5

b)

1.0

c)

1

d)

0

10.

What is the result of 3.0/2 in Java?

a)

1.5

b)

1.0

c)

1

d)

0

11.

What is the result of 3%2?

a)

1

b)

1.5

c)

1.0

d)

0

12.

What is the result of 2%1?

a)

0

b)

1

c)

2

d)

This cannot be calculated.

13.

What is the difference between primitive variables and Object reference variables?

a)

Primitive variables hold a variable's value, whereas Object reference variables do not a value, they point to it .

b)

Primitive variables take up a specific amount of memory, whereas the amount of memory an Object reference can take up varies.

c)

Both answers are correct.

14.

Where does modulus fall within the PEMDAS order of operations?

a)

After multiplication and division

b)

Before multiplication and division

c)

At the same level of multiplication and division

d)

Whenever you feel like it.

15.

Which statement is an incorrect attempt at instantiating a String object?

a)

new String("hi!");

b)

String s = new String("hi!");

c)

String s = "hi!";

d)

String s = String("hi!");

16.
What are the only two numbers you can use in binary?
a)
0 and 1
b)
1 and 2
c)
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
d)
1, 2, 4, 8, 16
17.
How is our number system different from the binary system?
a)
Our number system is base-5; the binary system is base-3
b)
Our number system is base-10; the binary system is base-2
c)
Our number system is base-10; the binary system is base-1
d)
Our number system is base 100; the binary system is base-2
18.
Your computer's code for the letter A is 01000001. Can you infer what the letter B would be?
a)
10010
b)
01000010
c)
01010110
d)
00000001
19.
8 bytes = 1 bit
a)
TRUE
b)
FALSE
20.

Data types hold the memory address of where the data is stored:

a)

null

b)

class

c)

primitive

d)

alphanumeric

21.

A variable that goes out of scope is

a)

garbage collected

b)

tested

c)

referenced

d)

instantiated

22.

True/False: It is possible to change the length of arrays during run time

a)

True

b)

False

23.

True/False: Arrays can hold more than one type of data

a)

True

b)

False

24.

Is the following binary number Even or Odd:

0111001

a)

even

b)

odd

25.

The elements in arrays of type double are initialized to

a)

null

b)

0

c)

0.0

d)

they are not initialized

26.

String [] name = { "Anne"};

What is the value of name.length;

a)

0

b)

1

c)

3

d)

4

e)

5

27.

String [] fruits = {"apple", "peach", "banana", "tomato"};

What is fruits[2].length() equal?

a)

4

b)

5

c)

6

28.

what is 2 to the zero power?

a)

0

b)

1

c)

2

29.

What is the function of the break statement?

a)

A loop that contains the break statement is terminated and the program continues to execute.

b)

the break statement is used to return a value from a method.

c)

The break statement is used when the computer experiences a run-time error.

d)

The break statement should never be used.

30.

In base 8, what comes after 7?

a)

8

b)

10

c)

11

d)

17

31.

Which of the following is in 8 bit form?

a)

1000 0000

b)

1101

c)

11 1110

d)

8

32.

What does this statement do?

int [] nums = new int[8];

a)

creates an array of 8 integers called nums

b)

creates a single variable name nums that contains an 8 digit number

c)

creates a single variable named nums that is initialized to 8.

33.

String str1 = "bats";

String str2 = "buns";

str1.compareTo(str2)

a)

returns 0

b)

returns a positive number

c)

returns a negative number

34.

int n1 = 12;

int n2 = 5

int ans = n1/n2

What is the value at ans?

a)

1

b)

2

c)

2.4