Deck 9: Arrays
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/46
Play
Full screen (f)
Deck 9: Arrays
1
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;
sum = sum + num;
True
2
In a method call statement, when passing an array as an actual parameter, you use only its name.
True
3
The statementint[] list = new int[15];creates list to be an array of 14 components because array index starts at 0.
False
4
Given the declarationdouble[] numList = new double[20];the statementnumList[12] = numList[5] + numList[7];updates the content of the thirteenth component of the array numList.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
5
Java stores two-dimensional arrays in a row order form in computer memory.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
6
A single array can hold components of many different data types.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
7
When an array object is instantiated, its components are initialized to their default values.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
8
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 46 flashcards in this deck.
Unlock Deck
k this deck
9
In row processing, a two-dimensional array is processed one row at a time.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
10
The array index can be any nonnegative integer less than the array size.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
11
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.
int[][] beta = new int[10][5];In this declaration, the array alpha has more components than the array beta.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
12
Given the declaration int[] list = new int[50];the statementSystem.out.println(list[0] + "..." + list[49]);outputs all 50 components of the array list.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
13
If an array index is less than or equal to zero, an InvalidIndexException exception is thrown.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
14
Arrays have a fixed number of elements.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
15
When a boolean array object is instantiated, its components are initialized to false.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
16
In column processing, a two-dimensional array is processed one column at a time.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
17
You can create an array of reference variables to manipulate objects.
Unlock Deck
Unlock for access to all 46 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 46 flashcards in this deck.
Unlock Deck
k this deck
19
Only one-dimensional arrays can be passed as parameters.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
20
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 46 flashcards in this deck.
Unlock Deck
k this deck
21
int[] list = {1, 3, 5, 7};(int i = 0; i < list.length; i++)
If (list[i] > 5)
System.out.println(i + " " + list[i]);Which indices are in bounds for the array list, given the declaration in the accompanying figure?
A) 0, 1, 2, 3
B) 1, 2, 3, 4
C) 1, 3, 5, 7
D) 0, 1, 3, 5
If (list[i] > 5)
System.out.println(i + " " + list[i]);Which indices are in bounds for the array list, given the declaration in the accompanying figure?
A) 0, 1, 2, 3
B) 1, 2, 3, 4
C) 1, 3, 5, 7
D) 0, 1, 3, 5
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
22
The statement dataType[][][] arrayName; would declare a two-dimensional array.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
23
char[][] table = new char[10][5];How many columns are in the array seen in the accompanying figure?
A) 0
B) 5
C) 10
D) 15
A) 0
B) 5
C) 10
D) 15
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
24
char[][] table = new char[10][5];What is the value of table[2].length?
A) 0
B) 5
C) 10
D) 15
A) 0
B) 5
C) 10
D) 15
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
25
The method size in the class Vector returns the number of elements in the vector.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
26
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)
B) Only (ii)
C) Both are invalid
D) None of these
(i) 0 through 500
(ii) 0 through 499
A) Only (i)
B) Only (ii)
C) Both are invalid
D) None of these
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following is the array subscripting operator in Java?
A) .
B) {}
C) new
D) []
A) .
B) {}
C) new
D) []
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
28
int[] numList = new int[50];for (int i = 0; i <50; i++)
NumList[i] = 2 * i;
Num[10] = -20;
Num[30] = 8;
How many components are in the array numList seen in the accompanying figure?
A) 0
B) 30
C) 49
D) 50
NumList[i] = 2 * i;
Num[10] = -20;
Num[30] = 8;
How many components are in the array numList seen in the accompanying figure?
A) 0
B) 30
C) 49
D) 50
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
29
Vectors can be used to implement lists.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
30
char[][] table = new char[10][5];What is the value of table.length?
A) 0
B) 5
C) 10
D) 15
A) 0
B) 5
C) 10
D) 15
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
31
A Vector object can shrink during program execution.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
32
int[] numList = new int[50];for (int i = 0; i < 50; i++)
NumList[i]= 2 * i;
Num[10] = -20;
Num[30] = 8;
What is the index number of the last component in the array numList seen in the accompanying figure?
A) 0
B) 30
C) 49
D) 50
NumList[i]= 2 * i;
Num[10] = -20;
Num[30] = 8;
What is the index number of the last component in the array numList seen in the accompanying figure?
A) 0
B) 30
C) 49
D) 50
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
33
char[][] table = new char[10][5];How many rows are in the array seen in the accompanying figure?
A) 0
B) 5
C) 10
D) 15
A) 0
B) 5
C) 10
D) 15
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
34
Consider the following method definition.public static int strange(int[] list, int listSize, int item)
{
Int count = 0;
For (int j = 0; j(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.
{
Int count = 0;
For (int j = 0; j
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 46 flashcards in this deck.
Unlock Deck
k this deck
35
double[] as = new double[7];
Double[] bs;bs = as;How many objects are present after the code fragment in the accompanying figure is executed?
A) 1
B) 2
C) 7
D) 14
Double[] bs;bs = as;How many objects are present after the code fragment in the accompanying figure is executed?
A) 1
B) 2
C) 7
D) 14
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
36
Given the following method heading public static void mystery(int list[], int size)and the declarationint[] alpha = new int[75];Which of the following is a valid call to the method mystery?
A) mystery(alpha[75], 50);
B) mystery(alpha[], 50);
C) mystery(alpha, 40);
D) mystery(int[75], alpha)
A) mystery(alpha[75], 50);
B) mystery(alpha[], 50);
C) mystery(alpha, 40);
D) mystery(int[75], alpha)
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
37
Given the method heading public static void strange(int a, int b)and the declarationint[] 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]);
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 46 flashcards in this deck.
Unlock Deck
k this deck
38
char[][] table = new char[10][5];How many dimensions are in the array seen in the accompanying figure?
A) 1
B) 2
C) 5
D) 10
A) 1
B) 2
C) 5
D) 10
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
39
Only a fixed number of elements can be stored in a vector.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following declares an array of int named beta?
A) int beta;
B) int[] beta;
C) new int beta[];
D) int beta = int[];
A) int beta;
B) int[] beta;
C) new int beta[];
D) int beta = int[];
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
41
Which method would you most likely use to find the location of an element in the vector?
A) lastElement
B) elementAt
C) indexOf
D) size
A) lastElement
B) elementAt
C) indexOf
D) size
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
42
Which method of the class vector would you use to remove an element at a specific location?
A) removeAllElements
B) removeElement
C) removeElementAt
D) removeLocation
A) removeAllElements
B) removeElement
C) removeElementAt
D) removeLocation
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
43
In which package is the class Vector located?
A) java.io
B) java.lang
C) java.util
D) java.text
A) java.io
B) java.lang
C) java.util
D) java.text
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
44
Which method would you most likely use to add an element to an end of a vector?
A) insertElementAt
B) addElement
C) copyInto
D) lastElement
A) insertElementAt
B) addElement
C) copyInto
D) lastElement
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
45
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.
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 46 flashcards in this deck.
Unlock Deck
k this deck
46
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.
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 46 flashcards in this deck.
Unlock Deck
k this deck