Java Ch7 walkthrough

Ace your homework & exams now with Quizwiz!

12. Which of the following is a correct method header for receiving a two-dimensional array as an argument? a. public static void passMyArray(int[]myArray1, int[]myArray2) b. public static void passMyArray(int[][] myArray) c. public static void passMyArray[][](int myArray) d. public static void passMyArray(array myArray)

b

13. Which of the following import statements is required in order to use the ArrayList class? a. import java.util.Tools; b. import java.util.ArrayList; c. import java.util.Containers; d. import java.util.API;

b

16. Which of the following methods returns a string representing all of the items stored in an ArrayList object? a. show b. toString c. print d. getList

b

5. Java provides a mechanism known as a __________ which makes it possible to write a method that takes a variable number of arguments. a. variable-length argument list b. dynamic parameter list c. unary-signature template d. polymorphic byte code

a

14. Which method is used to determine the number of items stored in an ArrayList object? a. items b. listLength c. size d. volume

c

10. An array of String objects a. is arranged the same as an array of primitive objects b. is compressed to four bytes for each element c. must be initialized when the array is declared d. consists of an array of references to String objects

d

23. What will be the result after the following code is executed? final int ARRAY_SIZE = 5; float[] x = float[ARRAY_SIZE]; for (i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; } a. A runtime error will occur. b. All the values in the array will be initialized to 10.0. c. All the values in the array except the first will be set to 10.0. d. The code contains a syntax error and will not compile.

d

34. When an array of objects is declared but not initialized, the array values are set to 0. t/f

f

40. The Java compiler will display an error message when it processes a statement that uses an invalid subscript. t/f

f

29. Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE]; a. It declares array1 to be a reference to an array of long values. b. It will allow valid subscripts in the range of 0 through 9. c. It creates an instance of an array of ten long values. d. All of these are true.

d

3. A partially filled array is normally used a. when only a very small number of values need to be stored b. when you know how many elements will be in the array but not what the values are c. with an accompanying parallel array d. with an accompanying integer value that holds the number of items stored in the array

d

4. When an array is passed to a method a. it is passed just as any other object would be passed b. the method has direct access to the original array c. a reference to the array is passed d. All of these are true

d

9. A(n) __________ is used as an index to pinpoint a specific element within an array. a. boolean value b. element c. range d. subscript

d

11. You can use the __________ method to replace an item at a specific location in an ArrayList. a. set b. remove c. replace d. add

a

15. The __________ method removes an item from an ArrayList at a specific index. a. remove b. pop c. deleteAt d. clear

a

2. A ragged array is a. a two-dimensional array where the rows have different numbers of columns b. a one-dimensional array for which the number of elements is unknown c. a two-dimensional array for which the number of rows is unknown d. a partially initialized two-dimensional array of ranged values

a

24. For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"}; a. a reference to the String object containing "ghi" b. "ghi" c. a reference to the String object containing "def" d. "def"

a

7. In order to do a binary search on an array a. the array must first be sorted b. you must first do a sequential search to be sure the element you are looking for is there c. the values of the array must be numeric d. All of these are true

a

21. What would be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5}; a. An array of 6 values, all initialized to 0 and referenced by the variable x will be created. b. An array of 6 values, ranging from 0 through 5 and referenced by the variable x will be created. c. The variable x will contain the values 0 through 5. d. A compiler error will occur.

b

26. What would be the result after the following code is executed? int[] numbers = {50, 10, 15, 20, 25, 100, 30}; int value = 0; for (int i = 1; i < numbers.length; i++) value += numbers[i]; a. The value variable will contain the average of all the values in the numbers array. b. The value variable will contain the sum of all the values in the numbers array. c. The value variable will contain the lowest value in the numbers array. d. The value variable will contain the highest value in the numbers array.

b

6. The binary search algorithm a. is less efficient than the sequential search algorithm b. will cut the portion of the array being searched in half each time it fails to locate the search value c. will have a maximum number of comparisons equal to the number of elements in the array d. will, normally, have the number of comparisons that is half the number of elements in the array

b

1. A search algorithm a. arranges elements in ascending order b. arranges elements in descending order c. is used to locate a specific item in a collection of data d. is rarely used with arrays

c

17. Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList? a. set b. store c. add d. insert

c

18. To return an array of long values from a method, which return type should be used for the method? a. long[ARRAY_SIZE] b. array c. long[] d. long

c

19. Which of the following is a valid declaration for a ragged array with five rows but no columns? a. int[][] ragged = new int[5]; b. int[][] ragged = new int[][5]; c. int[][] ragged = new int[5][]; d. int[] ragged = new int[5];

c

20. If numbers is a two-dimensional array, which of the following would give the number of columns in row r? a. numbers.length b. numbers.length[r] c. numbers[r].length d. numbers[r].length[r]

c

22. Given the following two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9]; a. The numbers array has 54 rows. b. The numbers array has 15 rows. c. The numbers array has 6 rows and 9 columns. d. The numbers array has 6 columns and 9 rows.

c

25. What would be the result after the following code is executed? 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]; } a. The value variable will contain the average of all the values in the numbers array. b. The value variable will contain the sum of all the values in the numbers array. c. The value variable will contain the lowest value in the numbers array. d. The value variable will contain the highest value in the numbers array.

c

27. 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. 95 b. 84 c. 94 d. 93

c

30. What does <String> specify in the following statement? ArrayList<String> nameList = new ArrayList<String>(); a. It specifies that String objects may not be stored in the ArrayList object. b. It specifies that everything stored in the ArrayList object will be converted to a String object. c. It specifies that only String objects may be stored in the ArrayList object. d. It specifies that the ArrayList will be converted to a String array.

c

8. The sequential search algorithm a. returns 1 if the value being searched for is found or -1 if the value is not found b. requires the array to be ascending order c. uses a loop to sequentially step through an array, starting with the first element d. All of these are true

c

28. What does the following statement do? double[] array1 = new double[10]; a. It declares array1 to be a reference to an array of double values. b. It will allow valid subscripts in the range of 0 through 9. c. It creates an instance of an array of ten double values. d. It does all of these.

d

9. A sorting algorithm is used to locate a specific item in a larger collection of data. t/f

f

31. An ArrayList object automatically expands in size to accommodate the items stored in it. t/f

t

32 Java does not limit the number of dimensions an array may have. t/f

t

33. The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line. t/f

t

35. To determine if two arrays are equal you must compare each of the elements of the two arrays. t/f

t

36. A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order. t/f

t

7. Objects in an array are accessed with subscripts, just like any other data type in an array. t/f

t

8. 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. t/f

t


Related study sets

Chapter 9 Psychology-Intelligence, Aptitude, and Cognitive Abilities

View Set