Starting Out with Java: From Control Structures through Data Structures, 1e, Chapter 8: Arrays

Ace your homework & exams now with Quizwiz!

C) With an accompanying integer value that holds the number of items stored in the array

A partially-filled array is normally used A) When you know how many elements will be in the array B) With an accompanying parallel array C) With an accompanying integer value that holds the number of items stored in the array D) To display array elements

C) A two-dimensional array when the rows are of different lengths

A ragged array is A) A two-dimensional array for which the number of rows is unknown B) A one-dimensiona array for which the number of elements is unknown C) A two-dimensional array when the rows are of different lengths D) There is no such thing as a ragged array

B) public static void passArray(int [ ][ ] intArray)

Which of the following is a correct method header for receiving a two-dimensional array as an argument? A) public static void passArray(int[1,2] intArray) B) public static void passArray(int [ ][ ] intArray) C) public static void passArray(int[1],[2] intArray) D) public static void passArray(int[ ], int[ ]intArray)

B) public static void passArray(int [ ][ ] intArray)

Which of the following is a correct method header for receiving a two-dimensional array as an argument? A) public static void passArray(int[2] intArray) B) public static void passArray(int [ ][ ] intArray) C) public static void passArray(int[1][2] intArray) D) public static void passArray(int[ ] intArray, int[ ]intArray)

C) int[ ][ ] ragged = new int[5][ ];

Which of the following is a valid declaration for a ragged array, after which you would declare each row? A) int[ ] ragged = new int[5]; B) int[ ][ ] ragged = new int[5][6]; C) int[ ][ ] ragged = new int[5][ ]; D) int[ ][ ] ragged = new int[ ][5];

C) A reference to the String "ghi"

For the following code, what would be the value of str[2]? String[ ] str = {"abc", "def", "ghi", "jkl"}; A) "ghi" B) "def: C) A reference to the String "ghi" D) A reference to the String "def:"

D) str[0].toUpperCase();

Given String[ ] str has been initialized, to convert all the characters in the String str[0] to upper case, use the following statement: A) str.uppercase(); B) str[0].upperCase(); C) str.toUpperCase(); D) str[0].toUpperCase();

B) The array numbers has 6 rows and 9 columns

Given the following two-dimensional array declaration, which statement is true? int [ ] [ ] numbers = new int [6] [9]; A) The array numbers has 6 columns and 9 rows B) The array numbers has 6 rows and 9 columns C) The array numbers has 15 rows D) The array numbers has 54 rows

C) 0-14

If final int sub = 15 and int[ ] x = new int[sub], what would be the range of subscript values that could be used with x[ ]? A) 1-15 B) 1-14 C) 0-14 D) 0-15

D) numbers[r].length

If numbers is a two-dimensional array, which of the following would give the length of row, r? A) numbers.length B) numbers.length[r] C) numbers[r].length[r] D) numbers[r].length

D) for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++} total += numbers[row][col]; }

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.length; col++} total += numbers[row][col]; } C) for (int row = 0; row < numbers[row].length; row++) { for (int col = 0; col < numbers.length; col++} total += numbers[row][col]; } D) for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++} total += numbers[row][col]; }

A) Consists of an array of references to String objects

In memory, an array of String objects A) Consists of an array of references to String objects B) Is arranged the same as an array of primitive objects C) Consists of elements, each of which is a String D) Must be initialized when the array is declared

D) All of the above

The following statements final int ARRAY_SIZE = 10; long[ ] array1 = new long[ARRAY_SIZE]; A) Declares array1 to be a reference to an array of long values B) Creates an instance of an array of 10 long values C) Will allow valid subscripts in the range of 0-9 D) All of the above

C) Uses a loop to sequentially step through an array, starting with the first element

The sequential search algorithm A) Requires the array to be ordered B) Returns the value it was searching for C) Uses a loop to sequentially step through an array, starting with the first element D) Will not execute, if the element is not in the array

D) All of the above

The statement: 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 the above

B) long[ ]

To return an array of long values from a method, use ________ as the return type for the method. A) long B) long[ ] C) long[array_size] D) [ ]long

A) import java.util.Scanner

To use the Scanner utility, you must A) import java.util.Scanner B) import.java.Swing C) import java.Scanner.util D) import.java.Arrays

False

True / False If a[ ] and b[ ] are two integer arrays, then if( a == b) compares the array contents.

True

True / False Java does not limit the number of dimensions that an array may have.

False

True / False Java limits the number of dimensions that an array may have to 15.

True

True / False Objects in an array are accessed with subscripts, just like any other data type in an array.

True

True / False When an array of objects is declared, but not initialized, the array values are set to null.

True

True / False: To compare the contents of two arrays, you must compare the elements of the two arrays.

A) 94

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) 94 B) 84 C) 93 D) 95

B) A reference to an array of float values

What will be returned from the following method? public static float[ ] getValue(int x) A) A float value B) A reference to an array of float values C) An integer D) A reference to an array of integers

A) An array of 6 values ranging from 0-5 and referenced by the variable x will be created

What will be the result of executing the following code? int[ ] x = {0, 1, 2, 3, 4, 5}; A) An array of 6 values ranging from 0-5 and referenced by the variable x will be created B) A compilation error will occur C) The program will crash when it is executed D) The value of x[0] will be 15 and x[1] - x[5] will be set to 0

C) The program will crash when it is executed

What will be the results of the following code? final int ARRAY_SIZE = 5; float[ ] x = new float[ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; } A) All the values in the array are initialized to 10.0 B) All the values, except the first, are set to 10.0 C) The program will crash when it is executed D) There will be a compilation error

C) 38

What will be the value for x[1] after the following code is executed? int[ ] x = {22, 33, 44}; arrayProcess(x); ... public static void arrayProcess(int[ ] a) { for(int k = 0; k < 3; k++) { a[k] = a[k] + 5; } } A) 27 B) 33 C) 38 D) 49

B) 33

What will be the value for x[1] after the following code is executed? int[ ] x = {22, 33, 44}; arrayProcess(x[1]); ... public static void arrayProcess(int a) { a = a + 5; } A) 27 B) 33 C) 38 D) 49

B) 180

What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[ ] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; } A) 170 B) 180 C) 190 D) 200

C) 60

What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[ ] x = new int[SUB]; int y = 20; for(int i = 0; i < SUB; i++) { x[i] = y; y += 5; } A) 50 B) 55 C) 60 D) 65

B) x[ ] = {36, 78, 12, 24} and y[ ] = {36, 78, 12, 24}

What would be the results after the following code was executed? int[ ] x = {23, 55, 83, 19}; int[ ] y = {36, 78, 12, 24}; for(int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x[a]; } A) y[ ] = {23, 55, 83, 19} and x[ ] = {36, 78, 12, 24} B) x[ ] = {36, 78, 12, 24} and y[ ] = {36, 78, 12, 24} C) x[ ] = {23, 55, 83, 19} and y[ ] = {23, 55, 83, 19} D) This is a compilation error

B) x[ ] = {36, 78, 12, 24} and y[ ] = {36, 78, 12, 24}

What would be the results after the following code was executed? int[ ] x = {23, 55, 83, 19}; int[ ] y = {36, 78, 12, 24}; x = y; y = x; A) y[ ] = {23, 55, 83, 19} and x[ ] = {36, 78, 12, 24} B) x[ ] = {36, 78, 12, 24} and y[ ] = {36, 78, 12, 24} C) x[ ] = {23, 55, 83, 19} and y[ ] = {23, 55, 83, 19} D) This is a compilation error

D) This would cause the program to crash

What would be the results of the following code? int[ ] array1 = new int[25]; ... // Code that will put values in arrat1 int value = 0; for (int a = 0; a <= array1.length; a++) { value += array1[a]; value = array1[a]; } A) value contains the highest value in array1 B) value contains the lowest value in array1 C) value contains the sum of all the values in array1 D) This would cause the program to crash

B) value contains the lowest value in array1

What would be the results of the following code? int[ ] array1 = new int[25]; ... // Code that will put values in arrat1 int value = array1[0]; for (int a = 1; a < array1.length; a++) { if (array1[a] < value) value = array1[a]; } A) value contains the highest value in array1 B) value contains the lowest value in array1 C) value contains the sum of all the values in array1 D) value contains the average of the values in array1

A) a = 5

What would be the results of the following code? int[ ] x = {55, 33, 88, 22, 99, 11, 44, 66, 77}; int a = 10; if(x[2] > x[5]) a = 5; else a = 8; A) a = 5 B) a = 8 C) a = 10 D) This is a compilation error, you cannot compare array elements

D) All of the above

When an array is passed to a method A) A reference to the array is passed B) It is passed just as an object C) The method has direct access to the original array D) All of the above

C) The method does not have direct access to the original array

When an individual element of an array is passed to a method A) A reference to the array is passed B) It is passed just as an object C) The method does not have direct access to the original array D) All of the above

C) for (int i = 0; i < names.length; i++) System.out.println(names[i].length());

Which of the following statements is a valid for statement, given the following? String[ ] names = {"abc", "def", "ghi", "jkl"}; A) for (int i = 0; i < names.length; i++) System.out.println(names[i].length); B) for (int i = 0; i < names.length(); i++) System.out.println(names[i].length); C) for (int i = 0; i < names.length; i++) System.out.println(names[i].length()); D) for (int i = 0; i < names.length(); i++) System.out.println(names[i].length());


Related study sets

Unit IV Recitation Quizzes and Learning Objectives

View Set

Chapter 16: Emotional and Social Development in Middle Adulthood

View Set

Chapter 3. Understanding the Organization's Environment

View Set

Psych EAQs 1-5 Foundations and Practice of Mental Health

View Set