Java Ch. 7 Quiz

25 July 2022
4.7 (114 reviews)
30 test answers

Unlock all answers in this set

Unlock answers (26)
question
What does the following statement do? double[] array1 = new double[10]; a. Declares array1 to be a reference to an array of double values b. Creates an instance of an array of 10 double values c. Will allow valid subscripts in the range of 0 - 9 d. All of these
answer
d. All of these
question
To return an array of long values from a method, use this as the return type for the method. a. long[ARRAY_SIZE] b. long[] c. long d. []long
answer
b. long[]
question
It is common practice to use a ________ variable as a size declarator. a. final b. static c. reference d. boolean
answer
a. final
question
If numbers is a two-dimensional array, which of the following would give the length of row r? a. numbers[r].length[r] b. numbers.length c. numbers.length[r] d. numbers[r].length
answer
d. numbers[r].length
question
Subscript numbering always starts at what value? a. 0 b. 1 c. -1 d. None of these
answer
a. 0
question
What do you call the number that is used as an index to pinpoint a specific element within an array? a. global unique identifier b. element c. subscript d. argument
answer
c. subscript
question
Java performs ________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array. a. active array sequencing b. buffer overrun protection c. array bounds checking d. scope resolution binding
answer
c. array bounds checking
question
The following statement creates an ArrayList object. What is the purpose of the notation? ArrayList arr = new ArrayList(); a. It specifies that String objects may not be stored in the ArrayList object. b. It specifies that the get method will return only String objects. c. It specifies that everything stored in the ArrayList object will be converted to a String. d. It specifies that only String objects may be stored in the ArrayList object.
answer
d. It specifies that only String objects may be stored in the ArrayList object.
question
What will be returned from the following method? public static float[] getValue(int x) a. An array of float values b. An array of integers c. A float value d. An integer
answer
a. An array of float values
question
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"}; a. A reference to the String "def" b. A reference to the String "ghi" c. "def" d. "ghi"
answer
b. A reference to the String "ghi"
question
In order to do a binary search on an array: a. the values of the array must be numeric b. the array must first be sorted in ascending order c. you must first do a sequential search of the array to assure the element you are looking for is there d. there are no requirements
answer
b. the array must first be sorted in ascending order
question
In Java, you do not use the new operator when you use a(n): a. array size declarator b. initialization list c. two-dimensional array d. All of these
answer
b. initialization list
question
This indicates the number of elements, or values, the array can hold. a. the array's data type b. the array's size declarator c. the new operator d. the version of Java
answer
b. the array's size declarator
question
What will be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5}; a. The program will crash when it is executed. b. A compilation error will occur. c. An array of 6 values ranging from 0 through 5 and referenced by the variable x will be created. d. The value of x[1] will be 0, x[2] will be 0, x[3] will be 0, x[4] will be 0, x[5] will be 0, and x[6] will be 0.
answer
c. An array of 6 values ranging from 0 through 5 and referenced by the variable x will be created.
question
What is the value of scores[2][3] in the following array? int [][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} }; a. 84 b. 94 c. 95 d. 93
answer
b. 94
question
Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement: a. str[0].upperCase(); b. str.toUpperCase(); c. str[0].toUpperCase(); d. str.uppercase();
answer
c. str[0].toUpperCase();
question
The binary search algorithm: a. will cut the portion of the array being searched in half each time the loop fails to locate the search value b. will have an average of N/2 comparisons, where N is the number of elements in the array c. is less efficient than the sequential search algorithm d. will have a maximum number of comparisons equal to the number of elements in the array
answer
a. will cut the portion of the array being searched in half each time the loop fails to locate the search value
question
This ArrayList class method deletes an item from an ArrayList. a. erase b. remove c. purge d. delete
answer
b. remove
question
Given the following two-dimensional array declaration, which statement is TRUE? int [][] numbers = new int [6] [9]; a. The array numbers has 54 rows. b. The array numbers has 6 columns and 9 rows. c. The array numbers has 15 rows. d. The array numbers has 6 rows and 9 columns.
answer
d. The array numbers has 6 rows and 9 columns.
question
Each array in Java has a public field named ________ that contains the number of elements in the array. a. capacity b. limit c. size d. length
answer
d. length
question
The ArrayList class is in this package. a. java.arraylist b. java.util c. java.lang d. java.array
answer
b. java.util
question
The sequential search algorithm: a. must always be implemented as a method b. uses a loop to sequentially step through an array, starting with the first element c. requires the array to be ordered d. will not execute, if the element is not in the array
answer
b. uses a loop to sequentially step through an array, starting with the first element
question
A search algorithm: a. arranges elements in descending order b. is a way to locate a specific item in a larger collection of data c. is rarely used with arrays d. arranges elements in ascending order
answer
b. is a way to locate a specific item in a larger collection of data
question
By default, Java initializes array elements with what value? a. 0 b. 1 c. 100 d. -1
answer
a. 0
question
What do you normally use with a partially-filled array? a. A class that does nothing but manage the array b. An accompanying parallel array c. An accumulator d. An accompanying integer value that holds the number of items stored in the array
answer
d. An accompanying integer value that holds the number of items stored in the array
question
If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array? a. for (int row = 1; row < numbers.length; row++) { for (int col = 1; col < numbers.length; col++) total += numbers [row][col]; b. for (int row = 0; row < numbers.length; row++) { for int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; } c. for (int for = 0; numbers.length; row++) { for (int col = 0; col < numbers.length; col++) total += numbers[row][col]; } d. for (int row = 0; row < numbers[row].length; row++) { for (int col = 0; col < numbers.length; col++) total += numbers[row][col]; }
answer
b. for (int row = 0; row < numbers.length; row++) { for int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }
question
A ragged array is: a. a two-dimensional array for which the number of rows is unknown b. a one-dimensional array for which the number of elements is unknown c. a two-dimensional array where the rows are of different lengths d. There is no such thing as a ragged array
answer
c. a two-dimensional array where the rows are of different lengths
question
If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]? a. 1 through 14 b. 1 through 15 c. 0 through 15 d. 0 through 14
answer
d. 0 through 14
question
This ArrayList class method is used to insert an item into an ArrayList. a. store b. insert c. putItem d. add
answer
d. add
question
In memory, an array of String objects: a. consists of elements, each of which is a String object b. must be initialized when the array is declared c. is always implemented as a ragged array d. consists of elements, each of which is a reference to a String object
answer
d. consists of elements, each of which is a reference to a String object