wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Arrays

Total questions: 20

Worksheet time: 16mins

Name
Class
Date
1.

Which of the following will create an out of bounds error? (select 2)

a)
b)
c)
d)
2.

Which value is not valid as an index for the following array?

a)

0

b)

5

c)

10

d)

9

3.

Java array indexes start at 0.

a)

True

b)

False

4.

What is the value of nums[3]?

(a)  

5.

Which is the correct way to declare an array of 10 integers? (select 2)

a)

b)

c)

d)

6.

What is the correct way to assign 4 to the 3rd position of the nums1 array?

a)

b)

c)

d)

7.

What is the index of the 12 in this array?

(a)  

8.

What number is at index 6?

(a)  

9.

What is the value of nums[4] after this code is executed?

a)

4

b)

44

c)

40

d)

10

10.

What is the value of nums[5] after this code is executed?

a)

10

b)

50

c)

55

d)

5

11.

What is the length of the following array: int[ ] data = { 12, 34, 9, 0, -62, 88 };

a)

5

b)

6

c)

88

d)

8

12.

A Java array can hold multiple types of data.

a)

True

b)

False

13.

What is the result of this code executing?

a)

nums[1] and nums[2] will both have the original nums[2] value.

b)

nums[1] and nums[2] will both have the original nums[1] value.

c)

nums[2] and nums[1] swap values.

d)

nothing changes

14.

Which of the following is FALSE about arrays on Java

a)

The size of an array can be changed after creation.

b)

Array inexes must be integers.

c)

Arrays can hold Strings.

d)

Arrays can hold doubles.

15.

(a)   is a collection of elements used to store the same type of data.

16.

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)

There are no correct.

17.

For the array:

int stats[5];

What is the range of the index?

a)

1-5

b)

0-4

c)

1-4

d)

0-5

18.

for(int i=0; i<10; i++)           

numbers[i] = 2 * i + 1;

// Which index of the array holds the value of 7?

a)

7

b)

6

c)

3

d)

1

19.

What is the error in the following code fragment?

double [] average = new double [20];

average[20] = 15.25;

a)

A cast is required

b)

Double not found

c)

Array out of bounds error

d)

Data not initialized

20.

An array declaration can optionally omit the new specifier and explicit size setting if it contains a comma-delimited _______________ inside a set of _______________ after the assignment operator, which will imply its size.

a)

initialization list, parentheses

b)

initialization list, curly braces

c)

parameter list, parentheses

d)

None of these