Deck 9: Arrays

Full screen (f)
exit full mode
Question
Suppose that you have the following declaration. int[] alpha = new int[50]; int[][] beta = new int[10][5]; In this declaration, the array alpha has more components than the array beta.
Use Space or
up arrow
down arrow
to flip the card.
Question
When a boolean array object is instantiated, its components are initialized to false.
Question
Given the declaration int[] list = new int[50]; the statement System.out.println(list[0] + "..." + list[49]); outputs all 50 components of the array list.
Question
Given the declaration double[] numList = new double[20]; the statement numList[12] = numList[5] + numList[7]; updates the content of the thirteenth component of the array numList.
Question
If a method has both a variable length formal parameter and other types of formal parameters, then the variable length formal parameter must be the first formal parameter of the formal parameter list.
Question
In row processing, a two-dimensional array is processed one row at a time.
Question
You can create an array of reference variables to manipulate objects.
Question
Only one-dimensional arrays can be passed as parameters.
Question
In a method call statement, when passing an array as an actual parameter, you use only its name.
Question
The statement int[] list = new int[15]; creates list to be an array of 14 components because array index starts at 0.
Question
Suppose list is a one-dimensional array, wherein each component is of the type int. The following for loop correctly finds the sum of the elements of list. int sum = 0; for (int num : list) sum = sum + num;
Question
Arrays have a fixed number of elements.
Question
The following statement creates alpha to be a two-dimensional array of 35 components. int[][] alpha = new int[20][15];
Question
Java stores two-dimensional arrays in a row order form in computer memory.
Question
When an array object is instantiated, its components are initialized to their default values.
Question
The array index can be any nonnegative integer less than the array size.
Question
A single array can hold components of many different data types.
Question
The base address of an array is the memory location of the first array component.
Question
In column processing, a two-dimensional array is processed one column at a time.
Question
If an array index is less than or equal to zero, an InvalidIndexException exception is thrown.
Question
Consider the following method definition. public static int strange(int[] list, int listSize, int item) {int count = 0; for (int j = 0; j < listSize; j++) if (list[j] == item) count++; return count;} Which of the following statements best describe the behavior of this method?

A) This method returns the number of values stored in list.
B) This method returns the sum of all the values of list.
C) This method returns the number of times item is stored in list.
D) This method can process an array of doubles.
Question
How many objects are present after the code fragment in the accompanying figure is executed?

A) 1
C) 7
B) 2
D) 14
Question
Only a fixed number of elements can be stored in a vector.
Question
Which of the following declares an array of int named beta?

A) int beta;
C) new int beta[];
B) int[] beta;
D) int beta = int[];
Question
What is the output of the following Java code? int[] list = {0, 5, 10, 15, 20}; for (int j = 0; j < 5; j++) System.out.print(list[j] + " "); System.out.println();

A) 0 1 2 3 4
C) 0, 5, 10, 15, 20
B) 0 5 10 15 20
D) 0 5 10 15
Question
How many rows are in the array seen in the accompanying figure?

A) 0
C) 10
B) 5
D) 15
Question
The method size in the class Vector returns the number of elements in the vector.
Question
What is stored in alpha after the following code executes? int[] alpha = new int[5]; for (int j = 0; j < 5; j++) {alpha[j] = 2 * j; if (j % 2 == 1) alpha[j - 1] = alpha[j] + j;}

A) alpha = {0, 2, 4, 6, 8}
C) alpha = {0, 3, 4, 7, 8}
B) alpha = {3, 2, 9, 6, 8}
D) alpha = {0, 2, 9, 6, 8}
Question
Which indices are in bounds for the array list, given the declaration in the accompanying figure?

A) 0, 1, 2, 3
C) 1, 3, 5, 7
B) 1, 2, 3, 4
D) 0, 1, 3, 5
Question
Which of the following is the array subscripting operator in Java?

A) .
C) new
B) {}
D) []
Question
Suppose you have the following declaration. double[] salesData = new double[500]; Which of the following range is valid for the index of the array salesData. (i) 0 through 500 (ii) 0 through 499

A) Only (i)
C) Both are invalid
B) Only (ii)
D) None of these
Question
How many components are in the array numList seen in the accompanying figure?

A) 0
C) 49
B) 30
D) 50
Question
Vectors can be used to implement lists.
Question
What is the value of alpha[4] after the following code executes? int[] alpha = new int[5]; for (int j = 0; j < 5; j++) alpha[j] = 2 * j - 1;

A) one
C) five
B) three
D) seven
Question
Given the following method heading public static void mystery(int list[], int size) and the declaration int[] alpha = new int[75]; Which of the following is a valid call to the method mystery?

A) mystery(alpha[75], 50);
C) mystery(alpha, 40);
B) mystery(alpha[], 50);
D) mystery(int[75], alpha)
Question
A Vector object can shrink during program execution.
Question
Given the method heading public static void strange(int a, int b) and the declaration int[] alpha = new int[20]; int[] beta = new int[25]; Which of the following is a valid call to the method strange?

A) strange(alpha[10], alpha[15]);
B) strange(alpha[5], beta);
C) strange(alpha[0], beta[25]);
D) strange(alpha, beta[20]);
Question
How many dimensions are in the array seen in the accompanying figure?

A) 1
C) 5
B) 2
D) 10
Question
The statement dataType[][][] arrayName; would declare a two-dimensional array.
Question
What is the index number of the last component in the array numList seen in the accompanying figure?

A) 0
C) 49
B) 30
D) 50
Question
What does the following statement do? Vector thisVector = new Vector();

A) It creates an empty vector to create a vector of Double objects.
B) It creates a vector with 10 elements to create a vector of Double objects.
C) This statement does not do anything.
D) It creates an array of Double objects.
Question
In which package is the class Vector located?

A) java.io
C) java.util
B) java.lang
D) java.text
Question
Suppose that sales is a two-dimensional array of 10 rows and 7 columns wherein each component is of the type int. Which of the following correctly finds the sum of the elements of the fifth row of sales?

A) int sum = 0;
B) int sum = 0;
C) int sum = 0;
D) int sum = 0;
Question
Which method of the class vector would you use to remove an element at a specific location?

A) removeAllElements
C) removeElementAt
B) removeElement
D) removeLocation
Question
How many columns are in the array seen in the accompanying figure?

A) 0
C) 10
B) 5
D) 15
Question
What is the value of table[2].length?

A) 0
C) 10
B) 5
D) 15
Question
What is the value of table.length?

A) 0
C) 10
B) 5
D) 15
Question
Which limitation of arrays does a vector overcome?

A) Arrays cannot increase in size; vectors can.
B) Arrays cannot be passed as parameters to methods; vectors can.
C) Arrays cannot be searched; vectors can.
D) There is a method that returns the length of a vector; there is no way to find the length of an array.
Question
Which method would you most likely use to add an element to an end of a vector?

A) insertElementAt
C) copyInto
B) addElement
D) lastElement
Question
Which method would you most likely use to find the location of an element in the vector?

A) lastElement
C) indexOf
B) elementAt
D) size
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: Arrays
1
Suppose that you have the following declaration. int[] alpha = new int[50]; int[][] beta = new int[10][5]; In this declaration, the array alpha has more components than the array beta.
False
2
When a boolean array object is instantiated, its components are initialized to false.
True
3
Given the declaration int[] list = new int[50]; the statement System.out.println(list[0] + "..." + list[49]); outputs all 50 components of the array list.
False
4
Given the declaration double[] numList = new double[20]; the statement numList[12] = numList[5] + numList[7]; updates the content of the thirteenth component of the array numList.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
If a method has both a variable length formal parameter and other types of formal parameters, then the variable length formal parameter must be the first formal parameter of the formal parameter list.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
In row processing, a two-dimensional array is processed one row at a time.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
You can create an array of reference variables to manipulate objects.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
Only one-dimensional arrays can be passed as parameters.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
In a method call statement, when passing an array as an actual parameter, you use only its name.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
The statement int[] list = new int[15]; creates list to be an array of 14 components because array index starts at 0.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
Suppose list is a one-dimensional array, wherein each component is of the type int. The following for loop correctly finds the sum of the elements of list. int sum = 0; for (int num : list) sum = sum + num;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
Arrays have a fixed number of elements.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
The following statement creates alpha to be a two-dimensional array of 35 components. int[][] alpha = new int[20][15];
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Java stores two-dimensional arrays in a row order form in computer memory.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
When an array object is instantiated, its components are initialized to their default values.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
The array index can be any nonnegative integer less than the array size.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
A single array can hold components of many different data types.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
The base address of an array is the memory location of the first array component.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
In column processing, a two-dimensional array is processed one column at a time.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
If an array index is less than or equal to zero, an InvalidIndexException exception is thrown.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
Consider the following method definition. public static int strange(int[] list, int listSize, int item) {int count = 0; for (int j = 0; j < listSize; j++) if (list[j] == item) count++; return count;} Which of the following statements best describe the behavior of this method?

A) This method returns the number of values stored in list.
B) This method returns the sum of all the values of list.
C) This method returns the number of times item is stored in list.
D) This method can process an array of doubles.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
How many objects are present after the code fragment in the accompanying figure is executed?

A) 1
C) 7
B) 2
D) 14
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
Only a fixed number of elements can be stored in a vector.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following declares an array of int named beta?

A) int beta;
C) new int beta[];
B) int[] beta;
D) int beta = int[];
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
What is the output of the following Java code? int[] list = {0, 5, 10, 15, 20}; for (int j = 0; j < 5; j++) System.out.print(list[j] + " "); System.out.println();

A) 0 1 2 3 4
C) 0, 5, 10, 15, 20
B) 0 5 10 15 20
D) 0 5 10 15
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
How many rows are in the array seen in the accompanying figure?

A) 0
C) 10
B) 5
D) 15
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
The method size in the class Vector returns the number of elements in the vector.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
What is stored in alpha after the following code executes? int[] alpha = new int[5]; for (int j = 0; j < 5; j++) {alpha[j] = 2 * j; if (j % 2 == 1) alpha[j - 1] = alpha[j] + j;}

A) alpha = {0, 2, 4, 6, 8}
C) alpha = {0, 3, 4, 7, 8}
B) alpha = {3, 2, 9, 6, 8}
D) alpha = {0, 2, 9, 6, 8}
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
Which indices are in bounds for the array list, given the declaration in the accompanying figure?

A) 0, 1, 2, 3
C) 1, 3, 5, 7
B) 1, 2, 3, 4
D) 0, 1, 3, 5
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following is the array subscripting operator in Java?

A) .
C) new
B) {}
D) []
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
Suppose you have the following declaration. double[] salesData = new double[500]; Which of the following range is valid for the index of the array salesData. (i) 0 through 500 (ii) 0 through 499

A) Only (i)
C) Both are invalid
B) Only (ii)
D) None of these
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
How many components are in the array numList seen in the accompanying figure?

A) 0
C) 49
B) 30
D) 50
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
Vectors can be used to implement lists.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
What is the value of alpha[4] after the following code executes? int[] alpha = new int[5]; for (int j = 0; j < 5; j++) alpha[j] = 2 * j - 1;

A) one
C) five
B) three
D) seven
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
Given the following method heading public static void mystery(int list[], int size) and the declaration int[] alpha = new int[75]; Which of the following is a valid call to the method mystery?

A) mystery(alpha[75], 50);
C) mystery(alpha, 40);
B) mystery(alpha[], 50);
D) mystery(int[75], alpha)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
A Vector object can shrink during program execution.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
Given the method heading public static void strange(int a, int b) and the declaration int[] alpha = new int[20]; int[] beta = new int[25]; Which of the following is a valid call to the method strange?

A) strange(alpha[10], alpha[15]);
B) strange(alpha[5], beta);
C) strange(alpha[0], beta[25]);
D) strange(alpha, beta[20]);
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
How many dimensions are in the array seen in the accompanying figure?

A) 1
C) 5
B) 2
D) 10
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
The statement dataType[][][] arrayName; would declare a two-dimensional array.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
What is the index number of the last component in the array numList seen in the accompanying figure?

A) 0
C) 49
B) 30
D) 50
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
What does the following statement do? Vector thisVector = new Vector();

A) It creates an empty vector to create a vector of Double objects.
B) It creates a vector with 10 elements to create a vector of Double objects.
C) This statement does not do anything.
D) It creates an array of Double objects.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
In which package is the class Vector located?

A) java.io
C) java.util
B) java.lang
D) java.text
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
Suppose that sales is a two-dimensional array of 10 rows and 7 columns wherein each component is of the type int. Which of the following correctly finds the sum of the elements of the fifth row of sales?

A) int sum = 0;
B) int sum = 0;
C) int sum = 0;
D) int sum = 0;
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
Which method of the class vector would you use to remove an element at a specific location?

A) removeAllElements
C) removeElementAt
B) removeElement
D) removeLocation
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
How many columns are in the array seen in the accompanying figure?

A) 0
C) 10
B) 5
D) 15
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
What is the value of table[2].length?

A) 0
C) 10
B) 5
D) 15
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
What is the value of table.length?

A) 0
C) 10
B) 5
D) 15
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
Which limitation of arrays does a vector overcome?

A) Arrays cannot increase in size; vectors can.
B) Arrays cannot be passed as parameters to methods; vectors can.
C) Arrays cannot be searched; vectors can.
D) There is a method that returns the length of a vector; there is no way to find the length of an array.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
Which method would you most likely use to add an element to an end of a vector?

A) insertElementAt
C) copyInto
B) addElement
D) lastElement
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
Which method would you most likely use to find the location of an element in the vector?

A) lastElement
C) indexOf
B) elementAt
D) size
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.