ch. 7
The sequential search algorithm
All of these - wrong returns 1 if the value being search for is found, otherwise it returns -1. - wrong
What will be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5};
An array of 6 values, ranging from 0 through 5 and referenced by the variable x, will be created.
What does the following statement do? double[] array1 = new double[10];
declares array1 to be a reference to an array of double values will allow valid subscripts in the range of 0 through 9 creates an instance of an array of 10 double values All of these
Which of the statements are true about the following code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE]
declares array1 to be a reference to an array of long values creates an instance of an array of 10 long values will allow valid subscripts in the range of 0 through 9 All of these
A(n) ________ is used as an index to pinpoint a specific element within an array.
element - wrong range - wrong
A sorting algorithm is used to locate a specific item in a larger collection of data.
false
The following import statement is required to use the ArrayList class:
import java.util.ArrayList;
You can use this ArrayList class method to insert an item at a specific location in an ArrayList.
insert - wrong
Which of the following is a valid declaration for a ragged array with five rows, but no columns?
int[][] ragged = new int[5]; - wrong int[][] ragged = new int[][5]; - wrong
To return an array of long values from a method, use this as the return type for the method.
long[]
What does <String> specify in the following statement? ArrayList<String> nameList = new ArrayList<String>();
It specifies that only String objects may be stored in the ArrayList object. - wrong
Given the following two-dimensional array declaration, which statement is true? int[] [] numbers = new int[6] [9];
The numbers array has 6 rows and 9 columns.
If numbers is a two-dimensional array, which of the following would give the number of columns in row r?
numbers[r].length
The ________ method removes an item from an ArrayList at a specific index.
remove
You can use the ________ method to replace an item at a specific location in an ArrayList.
set
You use this method to determine the number of items stored in an ArrayList object.
size
In order to do a binary search on an array,
the array must first be sorted in ascending order.
This method returns a string representing all of the items stored in an ArrayList object.
toString
A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.
true
An ArrayList object automatically expands in size to accommodate the items stored in it.
true
To determine if two arrays are equal, you must compare each of the elements of the two arrays.
true
A partially filled array is normally used
when a very small number of values need to be stored. - wrong
The binary search algorithm
will cut the portion of the array being searched in half each it fails to locate the search value.
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};
a reference to the String object containing "ghi"
A search algorithm
arranges elements in ascending order. - wrong arranges elements in descending order. - wrong
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} };
95 - wrong 84 - wrong
What will be the result of the following code? final int ARRAY_SIZE = 5; float [] x = float[ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; }
A runtime error will occur. - wrong All the values in the array will be initialized to 10.0. - wrong
Java does not limit the number of dimensions that an array may have.
true
Objects in an array are accessed with subscripts, just like any other data type in an array.
true
The Java compiler does not display an error message when it processes a statement that uses an invalid subscript.
true
The String[] args parameter in the main method header allows the program to receive arguments from the operating system command line.
true
Java provides a mechanism known as ________, which makes it possible to write a method that takes a variable number of arguments.
variable-length argument lists
When an array is passed to a method
it is passed just as any other object would be. the method has direct access to the original array. a reference to the array is passed. All of these
Which of the following is a correct method header for receiving a two-dimensional array as an argument?
public static void passMyArray(int[][] myArray)
What is a ragged array?
a two-dimensional array where the rows have a different number of columns
When an array of objects is declared, but not initialized, the array values are set to 0.
false
What will be the result of the following code? int[] numbers = {40, 3, 5, 7, 8, 12, 10}; int value = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < value) value = numbers[i]; }
The value variable will contain the lowest value in the numbers array.
What will be the result of the following code? int[] numbers = {50, 10, 15, 20, 25, 100, 30}; int value = 0; for (int i = 0; i < numbers.length; i++) value += numbers[i];
The value variable will contain the sum of all the values in the numbers array.
Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.
true
An array of String objects
consists of an array of references to String objects.