wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CSA Unit 3 Review

Total questions: 20

Worksheet time: 17mins

Name
Class
Date
1.
This is an array called values. What is the value of values.length?
a)
0
b)
5
c)
6
d)
7
2.
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
3.
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[];
4.
Based on the statement below, which of the following statements gives the length of the data array?
double[ ] data = new double[10];
a)
data.size()
b)
data.length
c)
data.size
d)
data.length()
5.
What is the error in the following code fragment?
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
6.
The first value of an array called quizzes can be accessed with which of the following statements?
a)
quizzes[1] = 100;
b)
quizzes[0] = 100;
c)
quizzes[zero] = 100;
d)
quizzes[one] = 100;
7.
String word = "A few good men";
What is word.length()?
a)
14
b)
15
c)
13
d)
12
8.
String word = "A few good men";
What is word.charAt(7) ?
a)
o
b)
g
c)
7
d)
good men
9.

String word = "A few good men";
What is word.indexOf('f')?

a)
2
b)
0
c)
1
d)
-1
10.
String word = "A few good men";
What is word.indexOf(“bad”)?
a)
0
b)
-1
c)
3
d)
6
11.
String word = "A few good men";
What is word.substring(3, 7) ?
a)
ew g
b)
ew go
c)
few
d)
few[space]
12.

What are the indexes for the array arr, given the following declaration:

int[] arr = {2, 4, 6, 8 }

a)
 0, 1, 2, 3
b)
 1, 2, 3, 4
c)
2, 4, 6, 8
d)
 0, 2, 4, 6
13.

What is the output of the following code fragment:

int[] arr = {2, 4, 6, 8 };

System.out.println( arr[0] + " " + arr[1] );

a)
 2 6
b)
8
c)
 2 4
d)
 6 8
14.

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

a)

The stopping condition should be changed to i < animals.length

b)

The stopping condition should be changed to i < animals.length - 1

c)

The stopping condition should be changed to i < animals[i].length

d)

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

15.

String sentence = "Hello World!";
What is sentence.indexOf("W")?

a)

6

b)

5

c)

7

d)

-1

16.

Given an array int[] numbers = {10, 20, 30, 40};
What is the value of numbers[2]?

a)

10

b)

20

c)

30

d)

40

17.

What is the output of the following code fragment:

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

System.out.println(fruits[1]);

a)

apple

b)

banana

c)

cherry

d)

fruits

18.

How would you get the value 6 out of the following array int[][] a = { {2, 4, 6, 8}, {1, 2, 3, 4}};?

a)

a[0][3]

b)

a[1][3]

c)

a[0][2]

d)

a[2][0]

e)

a[3][1]

19.

Given the following code segment, what is the value of sum after this code executes?

a)

4

b)

8

c)

9

d)

12

e)

10

20.

What are the contents of arr after the following code has been executed?

a)

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

b)

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

c)

{ {3, 2, 1}, {1, 4, 8}}

d)

{ {4, 4, 2}, {2, 4, 4}}

e)

{ {3, 2, 1}, {2, 4, 4}}