java 7

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Declaring an array reference variable does not create an array.

True

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

True

Once an array is created, its size cannot be changed.

True

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

True

To determine if two arrays are equal you must compare each of the elements of the two arrays.

True

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

True

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

In memory, an array of String objects __________. a. consists of elements, each of which is a reference to a String object 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

A

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. no requirements are necessary

A

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

A

What will be the results after the following code is executed? 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. a = 13

A

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

By default, Java initializes array elements to __________. a. 0 b. 100 c. -1 d. 1

A

Subscripting always starts with __________. a. 0 b. 1 c. -1 d. none of these

A

In Java, you do not use the new operator when you use a(n) ____________. a. array size declarator c. two-dimensional array b.initialization listd.any of these

B

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 15 c. 0 through 14 b.1 through 14d.0 through 15

C

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

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

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

False

An array can hold multiple values of several different types of data simultaneously.

False

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 c. scope resolution binding b. array bounds checking d. buffer overrun protection

B

The __________ indicates the number of elements the array can hold. a. new operator c. array's data type b. array's size declarator d. version of Java

B

The ___________ method is used to insert an item into an ArrayList. a. insert b. add c. store d. putItem

B

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]) b. public static void passArray(int [][]) c. public static void passArray(int[1],[2]) d. public static void passArray(int[], int[])

B

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

B

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

Each array in Java has a public field named __________ that contains the number of elements in the array.. a. size b. capacity c. length d. limit

C

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"

C

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

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

C

It is common practice to use a __________ variable as a size declarator. a. static c. final b.referenced.boolean

C

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. must always be implemented as a method

C

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

C

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

What will be the value of x[8] after the following code is 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

C

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

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

What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a <= array1.length; 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 code would cause the program to crash.

D

If a[] and b[] are two integer arrays, the expression a == b compares the array contents.

False

Java limits the number of dimensions that an array can have to 15.

False

An ArrayList object automatically expands in size to accommodate the items stored in it

True

Any items typed on the command line, separated by a 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

Java does not limit the number of dimensions an array may have.

True

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

What will be the results after the following code is executed? int[] array1 = new int[25]; ... // Code that will put values in array1 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 all the values in array1

B

What will be the value of x[8] after the following code is 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

B

What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a < array1.length; 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 code would cause the program to crash.

B

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

What would be the result after the following code is 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. x[] = {36, 78, 12, 24} and y[] = {23, 55, 83, 19} 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. Nothing. This is a compile error.

B

What would be the result after the following code is executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; x = y; y = x; a. x[] = {36, 78, 12, 24} and y[] = {23, 55, 83, 19} 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. Nothing. This is a compile error.

B

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

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

When an individual element of an array is passed to a method __________. a. a reference to the array is passed b. it is passed like any other variable c. the method does not have access to the original array d. All of these are true.

C

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

Which of the following for loops is valid, given the following declaration? 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());

C

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

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

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

D

Given that String[] str has been initialized, to get a copy of str[0] with all the characters converted to uppercase, you would use the __________ statement. a. str.uppercase(); c. str.toUpperCase(); b. str[0].upperCase(); d. str[0].toUpperCase();

D

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]; }

D

The ArrayList class is in the __________ package. a. java.arraylist c. java.array b. java.lang d. java.util

D

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

True


Set pelajaran terkait

Умственное воспитание

View Set