Professional Documents
Culture Documents
SKILLS WARM-UP
True 5. When an array object is instantiated, its components are initialized to their default
values.
False 6. The following statement creates alpha to be a two-dimensional array of 35
components.
int[][] alpha = new int[20][15];
False 7. In Java, the array index starts at 1.
False 8. Arrays can be initialized when they are created.
True 9. When an application contains an array and you want to use every element of the
array in some task, it is common to perform loops that vary the loop control variable
from 0 to one less than the size of the array.
True 10. Two-dimensional arrays generally contain data in table form.
SKILLS WORKOUT
Multiple Choice: Encircle the letter that corresponds to the correct answer.
int[] numList = new int[50];
num[10] = -20;
num[30] = 8;
a 1. What is the data type of the array numList above?
a. int c. list
b. new d. numList
d 2. How many components are in the array numList above?
a. 0 c. 49
b. 30 d. 50
c 3. What is the index number of the last component in the array numList above?
a. 0 c. 49
b. 30 d. 50
a 4. What is the value of numList.length in the array above?
a. 0 c. 49
b. 30 d. 50
a 5. What is the value at index 10 of the array numList?
a. -20 c. 20
b. 0 d. None of these
c 6. Consider the following statements:
int[] hits = {5, 7, 9, 11, 13, 15};
What is the number of elements in the array hits.
a. 0 c. 6
b. 5 d. 15
b. 3 d. 7
c 9. What is the value of alpha[3] after the following code executes?
int[] alpha = new int[5];
alpha[0] = 3;
for (int j = 1; j < 5; j++)
alpha[j] = alpha[j – 1] + 3;
a. 3 c. 12
b. 6 d. 15
a 10. Which of the following creates an array of 15 components of type double?
(i) double[] numList = new double[15];
(ii) double[] numList = new numList[15];
a. Only (i) c. Both (i) and (ii)
b. Only (ii) d. None of these
b 11. Which of the following can be used as an array subscript?
a. char c. double
b. int d. String
c 12. If you declare an array as follows, how do you indicate the final element of the array?
int[] num = new int[6];
a. num[0] c. num[5]
b. num[6] d. impossible to tell
b 13. If you declare an integer array as follows, what is the value of num[2]?
int[] num = {101, 202, 303, 404, 505, 606};
a. 101 c. 202
b. 303 d. 404
b 14. In the following array, what is the value of address[1][1]?
String address = {{ “123 Artacho St.” , “345 Alvear St.”},
{ “87 New St.” , “901 Rizal St.” }}
a. “123 Artacho St.” c. “345 Alvear St.”
b. “87 New St.” d. “901 Rizal St.”
d 15. In the following array, what is the value of code[2][1]?
char[][] code = { {‘A’, ‘D’, ‘M’},
{‘P’, ‘R’, ‘S’},
{‘U’, ‘V’, ‘Z’}};
a. P c. R
b. U d. V