NEW
Font size
S
M
L
XL
WorksheetsAP CSA Arrays
Total questions: 26
Worksheet time: 27mins
Name
Class
Date
1.
What does the term zero indexing mean?
a)
Ensuring there is not a DivideByZero Exception
b)
Assigning the first value in the array to zero
c)
Initializing a for loop to start at zero
d)
Labeling the first element of an array zero
2.
Values of different data types can be elements of the same array.
a)
True
b)
False
3.
What is valid syntax to construct an array?
a)
int[] arr1
b)
int[5] arr1 = new int[]
c)
int[] arr1 = new int[5]
4.
Arrays can only contain primitive data types.
a)
True
b)
False
5.
Once the int[] arr1 has been constructed, the length can be changed by:
a)
arr1.length = 5;
b)
arr1 = [5]
c)
arr1 = int[5]
d)
The length cannot be changed.
6.
Until a value is assigned to an element of a String array, what is the default value?
a)
Zero
b)
Space
c)
Null
d)
-1
7.
A method can accept an array as a parameter, and it can return an array.
a)
True
b)
False, a method cannot accept an array as a parameter.
c)
False, a method cannot return an array.
d)
False, arrays can never be used with methods.
8.
If values have not been assigned to elements of an integer array, the default value is:
a)
Zero
b)
Space
c)
Null
d)
-1
9.
This is an array called values. What is returned by values[5]?
a)
9
b)
12
c)
6
d)
8
10.
This is an array called values. What is the value of values.length?
a)
0
b)
5
c)
6
d)
7
11.
Index values of an array range from ______________.
a)
0 to length – 1
b)
1 to length
c)
0 to length
d)
0 to length + 1
12.
Create an array of 12 Strings called months.
a)
String[] months = new String[12];
b)
String months = new String[12];
c)
String[] months = new String[];
d)
String[12] months = new String[];
13.
Based on the statement below, which of the following statements gives the length of the data array?
double[ ] data = new double[10];
double[ ] data = new double[10];
a)
data.size()
b)
data.length
c)
data.size
d)
data.length()
14.
What is the error in the following code fragment?
double[ ] data = new double[20];
data[20] = 15.25;
double[ ] data = new double[20];
data[20] = 15.25;
a)
A cast is required
b)
data not initialized
c)
A two-dimensional array is required
d)
Out-of-bounds error
15.
To concatenate the programmer must:
a)
have quotations (" ")
b)
use the plus symbol +
c)
escape sequences (\t\n)
d)
use System.out.print( );
16.
The first value of an array called quizzes can be assigned with which of the following statements?
a)
quizzes[1] = 100;
b)
quizzes[0] = 100;
c)
quizzes[zero] = 100;
d)
quizzes[one] = 100;
17.
Which of the following statements outputs the fifth value in the quizzes array?
a)
System.out.println(quizzes[5]);
b)
quizzes[4];
c)
quizzes[5];
d)
System.out.println(quizzes[4]);
18.
String word = "A few good men";
What is word.length()?
What is word.length()?
a)
14
b)
15
c)
13
d)
12
19.
String word = "A few good men";
What is word.charAt(7) ?
What is word.charAt(7) ?
a)
o
b)
g
c)
7
d)
good men
20.
String word = "A few good men";
What is word.indexOf(“f”)?
What is word.indexOf(“f”)?
a)
2
b)
0
c)
1
d)
-1
21.
String word = "A few good men";
What is word.indexOf(“bad”)?
What is word.indexOf(“bad”)?
a)
0
b)
-1
c)
3
d)
6
22.
String word = "A few good men";
What is word.substring(3, 7) ?
What is word.substring(3, 7) ?
a)
ew g
b)
ew go
c)
few
d)
few[space]
23.
What are the legal indexes for the array
ar, given the following declaration:int[] ar = {2, 4, 6, 8 }a)
0, 1, 2, 3b)
1, 2, 3, 4c)
2, 4, 6, 8
d)
0, 2, 4, 624.
What is the output of the following code fragment:
int[] ar = {2, 4, 6, 8 }; System.out.println( ar[0] + " " + ar[1] ); a)
2 6b)
8
c)
2 4d)
6 825.
What does the ! operator mean?
a)
or
b)
and
c)
also
d)
not
26.
The == operator...
a)
Assigns a value to a variable.
b)
Checks equality between two things.
c)
Finds the sum of two variables.
d)
Finds the product of two variables.
Reset
