WorksheetsChapter 2-1: Array Part 1
Total questions: 12
Worksheet time: 6mins
What is an array?
A collection of variables of the same type stored in contiguous memory locations.
A collection of variables of different types stored in non-contiguous memory locations.
A collection of functions.
A type of loop structure.
Which of the following correctly declares an array in Java?
int array;
int array[10];
int[] array = new int[10];
array array[10];
What is the index of the first element in an array?
-1
0
1
The index is undefined
How do you access the third element in an array named arr in Java?
arr[3];
arr(3);
arr[2];
arr{3};
Which of the following statements correctly initializes an array of 5 integers to zero?
int[] arr = {0, 0, 0, 0, 0};
int[] arr = (0, 0, 0, 0, 0);
int[] arr = [0, 0, 0, 0, 0];
int[] arr = new int[5];
What is a multi-dimensional array?
An array with only one dimension.
An array that can store values of different types.
An array with more than one dimension, such as a 2D array.
An array that uses pointers.
How do you declare a two-dimensional array in Java?
int arr[2];
int[][] arr = new int[2][3];
int arr{2,3};
int arr(2,3);
What is the output of the following code?
int[] arr = {1, 2, 3};
System.out.println(arr[1]);
1
2
3
Error
How do you store the value 10 in the third element of an array named arr?
arr[3] = 10;
arr[2] = 10;
arr(3) = 10;
arr{2} = 10;
Which of the following is TRUE about array size in Java?
The size of an array is always fixed after its declaration.
The size of an array can be changed after its declaration.
Arrays do not have a size limit.
The size of an array is defined during the runtime.
What does the following array declaration signify?
int[][] arr = new int[5][4];
An array of 5 integers.
An array of 4 integers.
A 2D array with 5 rows and 4 columns.
A 2D array with 4 rows and 5 columns.
How do you retrieve the second element from a 2D array arr with 3 rows and 3 columns?
arr[2][1];
arr[1][2];
arr[1][1];
arr[0][1];
