wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CodeHS Arrays

Total questions: 18

Worksheet time: 9mins

Name
Class
Date
1.

What is the process of looping through every element in an array?

a)

iterating over the array

b)

looping over the array

c)

implementing over the array

d)

stringing over the array

2.

What does this code do?

a)

adds 1 to each element of the array

b)

finds the sum of the array

c)

prints the array to the screen and ends

d)

throws an exception

3.

What does this code do?

a)

adds 1 to each element of the array

b)

finds the sum of the array

c)

prints the array to the screen and ends

d)

throws an exception

4.
An array is;
a)
Shapes
b)
Sizes
c)
Options
d)
Lists of data
5.

What is first index value of an array?

a)

-1

b)

0

c)

1

d)

undefine

6.
What surrounds an array?
a)
Quotations
b)
Curly Brackets
c)
Parenthesis
d)
Square Brackets
7.
array = [1,2,3,4,5]
What is the length of this array?
a)
5
b)
4
c)
0
d)
125.4
8.

Which definition below best describe an array?

a)

An array is a function identifier that can hold more than one parameter.

b)

An array is a beam of light.

c)

An array is a special variable, which can hold more than one value at a time.

d)

An array is a special function, which can hold more than one value at a time.

9.
What are the legal indexes for the array ar, given the following declaration:
int[] ar = {2, 4, 6, 8 }
a)
 0, 1, 2, 3
b)
 1, 2, 3, 4
c)
2, 4, 6, 8
d)
 0, 2, 4, 6
10.
Which of the following are good examples of things to store as arrays or lists? 
I – A to-do list 
II – A grocery list 
III – A ball in a game of breakout 
IV – A list of balls in a game of breakout 
V – A loop counter variable
a)
II only
b)
III and V
c)
I, II, and IV
d)
I, II, III, IV, and V
11.
What does the following segment of code print out? int[] numArray = { 2, 7, 4, 12, 0, 2 };
System.out.println("Number: " + numArray[2]);
a)
Number: 2
b)
Number: 7
c)
Number: 4
d)
Number: 12
12.
What does the following segment of code print out? int[] numArray = { 2, 7, 4, 12, 0, 2 };
System.out.println("Number: " + numArray[0]);
a)
Number: 2
b)
Number: 7
c)
Number: 4
d)
Number: 12
13.
What does the following segment of code print out? int[] numArray = { 2, 7, 4, 12, 0, 2 };
System.out.println("Number: " + numArray[numArray.length - 1]);
a)
Number: 2
b)
Number: 0
c)
Number: 12
d)
Number: 6
14.
What does the following segment of code print out? int[] numArray = { 2, 7, 4, 12, 0, 2 };
System.out.println(numArray.length);
a)
4
b)
5
c)
6
d)
7
15.
What is the correct way to initialize an array with 10 positions?
a)
int numbers = new int[10];
b)
int[] numbers = new int[];
c)
int[10] numbers = new int[10];
d)
int[] numbers = new int[10];
16.
True or False:  An array can be store different types of data (like store both doubles and ints).
a)
True
b)
False
17.

In the following code segment, assume that the string str has been properly declared and initialized. The code segment is intended to print the number of strings in the array animals that have str as a substring. The code segment does not work as intended. Which of the following changes should be made so the code segment works as intended?

a)

The Boolean expression in the for loop header should be changed to i < animals.length.

b)

The Boolean expression in the for loop header should be changed to i < animals.length - 1.

c)

The Boolean expression in the for loop header should be changed to i < animals[i].length.

d)

The condition in the if statement should be changed to animals[i].equals(str).

e)

The condition in the if statement should be changed to animals[i].substring(str).

18.

Consider the following code segment. Which of the following represents the contents of the array arr after the code segment is executed?

a)

{0, 1, 2, 3, 4, 5, 6}

b)

{1, 1, 1, 1, 1, 1, 1}

c)

{1, 1, 3, 3, 5, 5, 7}

d)

{1, 2, 3, 4, 5, 6, 7}

e)

{2, 2, 4, 4, 6, 6, 7}