Font size
WorksheetsJava Arrays
Total questions: 20
Worksheet time: 16mins
Which of the following will create an out of bounds error? (select 2)
Which value is not valid as an index for the following array?
0
5
10
9
Java array indexes start at 0.
True
False
What is the value of nums[3]?
(a)
Which is the correct way to declare an array of 10 integers? (select 2)
What is the correct way to assign 4 to the 3rd position of the nums1 array?
What is the index of the 12 in this array?
(a)
What number is at index 6?
(a)
What is the value of nums[4] after this code is executed?
4
44
40
10
What is the value of nums[5] after this code is executed?
10
50
55
5
What is the length of the following array: int[ ] data = { 12, 34, 9, 0, -62, 88 };
5
6
88
8
A Java array can hold multiple types of data.
True
False
What is the result of this code executing?
nums[1] and nums[2] will both have the original nums[2] value.
nums[1] and nums[2] will both have the original nums[1] value.
nums[2] and nums[1] swap values.
nothing changes
Which of the following is FALSE about arrays on Java
The size of an array can be changed after creation.
Array inexes must be integers.
Arrays can hold Strings.
Arrays can hold doubles.
(a) is a collection of elements used to store the same type of data.
What are the legal indexes for the array ar, given the following declaration:
int[] ar = {2, 4, 6, 8 }
0, 1, 2, 3
1, 2, 3, 4
2, 4, 6, 8
There are no correct.
For the array:
int stats[5];
What is the range of the index?
1-5
0-4
1-4
0-5
for(int i=0; i<10; i++)
numbers[i] = 2 * i + 1;
// Which index of the array holds the value of 7?
7
6
3
1
What is the error in the following code fragment?
double [] average = new double [20];
average[20] = 15.25;
A cast is required
Double not found
Array out of bounds error
Data not initialized
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.
initialization list, parentheses
initialization list, curly braces
parameter list, parentheses
None of these
