wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

One Dimensional Array

Total questions: 14

Worksheet time: 11mins

Name
Class
Date
1.
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
2.

For the array:

int stats[3];

What is the range of the index?

a)

0 to 3

b)

0 to 2

c)

1 to 3

d)

0 to 4

3.

int [] nums = {2, 3, 5, 8, 9, 11};

How would you access the fourth element in nums?

a)

nums[4]

b)

nums[3]

c)

nums(4)

d)

nums(3)

4.
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;
5.
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]);
6.
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
7.
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[];
8.

What value is at index 1 in this array?

String[] names = {"Mack", "Dennis", "Dee", "Charlie"};

a)

Mack

b)

Dennis

c)

Dee

d)

Charlie

9.

What is the correct way to create an array with these three numbers: 12 8 15

a)

int[] = {12, 8, 15};

b)

int[] nums = {12 8 15};

c)

int[] nums = new {12, 8, 15};

d)

int[] nums = {12, 8, 15};

10.
What is returned by values[5]?
a)
9
b)
12
c)
6
d)
8
11.
for(int i=0; i<10; i++)
           numbers[i] = 2 * i + 1;
// Which index of the array holds the value of 5?
a)
1
b)
2
c)
3
d)
4
12.

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

13.

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

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