CNPP - Chapter 7 - Arrays and ArrayList

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

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[]?

0 through 14

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

180

What do you normally use with a partially-filled array?

An accompanying integer value that holds the number of items stored in the array

What would be the results of the following code? 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]; }

This would cause the program to crash

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

T

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.

array bounds checking

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

F

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

T

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

T

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?

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

Each array in Java has a public field named ____________ that contains the number of elements in the array.

length

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:

str[0].toUpperCase();

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;

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

Given the following two-dimensional array declaration, which statement is true? int [ ][ ] numbers = new int [6] [9];

The array numbers has 6 rows and 9 columns

By default, Java initializes array elements with what value?

0

What will be the value of 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; }

33

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

60

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

94

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};

A reference to the String "ghi"

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 will be returned from the following method?

An array of float values

What will be the results 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; }

An error will occur when the program runs.

The sequential search algorithm:

uses a loop to sequentially step through an array, starting with the first element

The ArrayList class is in this package.

java.util

To return an array of long values from a method, use this as the return type for the method.

long[ ]

You use this method to determine the number of items stored in an ArrayList object.

numberItems

If numbers is a two-dimensional array, which of the following would give the length of row r?

numbers[r].length

Which of the following is a correct method header for receiving a two-dimensional array as an argument?

public static void passArray(int [ ][ ])

The binary search algorithm:

will cut the portion of the array being searched in half each time the loop fails to locate the search value

A ragged array is:

a two-dimensional array where the rows are of different lengths

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

F

You can use this ArrayList class method to replace an item at a specific location in an ArrayList

set

What do you call the number that is used as an index to pinpoint a specific element within an array?

subscript

The following statement creates an ArrayList object. What is the purpose of the <String> notation? ArrayList<String> arr = new ArrayList<String>();

It specifies that only String objects may be stored in the ArrayList object.

In order to do a binary search on an array,

the array must first be sorted in ascending order

This indicates the number of elements, or values, the array can hold.

the array's size declarator

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

T

To compare the contents of two arrays, you must compare the elements of the two arrays.

T

Which of the following is a valid declaration for a ragged array?

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

A search algorithm:

is a way to locate a specific item in a larger collection of data

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

F

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

F

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

T

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

T

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

Declaring an array reference variable does not create an array.

T

In Java, you do not use the new operator when you use a(n):

initialization list

When an array is passed to a method:

a reference to the array is passed it is passed just as an object the method has direct access to the original array

This ArrayList class method is used to insert an item into an ArrayList.

add

In memory, an array of String objects

consists of elements, each of which is a reference to a String object.

It is common practice to use a ____________ variable as a size declarator.

final

Which of the following for loops is valid, given the following declaration? String[] names = {"abc", "def", "ghi", "jkl"};

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

You can use this ArrayList class method to insert an item at a specific location in an ArrayList.

store

What would be the results of the following code? 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]; }

value contains the lowest value in array1

When an individual element of an array is passed to a method:

the method does not have direct access to the original array

What will be the value of 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; } }

38

A partially-filled array is normally used

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

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 = 5

What does the following statement do? double[ ] array1 = new double[10];

Declares array1 to be a reference to an array of double values Creates an instance of an array of 10 double values Will allow valid subscripts in the range of 0 - 9

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 - 9

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

T

What would be the results of the following code? 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]; }

value contains the sum of all the values in array1

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

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

Subscript numbering always starts at what value?

0


संबंधित स्टडी सेट्स

Chapter 24: Asepsis/Infection Control

View Set

Unit 1: Hi, I'm Peter (Go For it A1)

View Set

OSHA: Emergency Action Plans & Fire Protection

View Set

Psychology in Addiction Exam 1 (Chapter 1-5)

View Set

Chapter 16 Marketing & Management

View Set

Med term questions for exam 3 (Digestive system)

View Set