Chapter 7 Quiz

¡Supera tus tareas y exámenes ahora con Quizwiz!

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

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

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 specify in the following statement? ArrayList nameList = new ArrayList();

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

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

The code contains a syntax error and will not compile

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

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"

When an array is passed to a method

a reference to the array is passed, it is passed just as any other object would be, and the method has direct access to the original array.

What is a ragged array?

a two-dimensional array where the rows have a different number of columns

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

add

An array of String objects

consists of an array of references to String objects

The following import statement is required to use the ArrayList class:

import java.util.ArrayList;

Which of the following is a valid declaration for a ragged array with five rows, but no columns?

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

A search algorithm

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

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

long[]

If numbers is a two-dimensional array, which of the following would give the number of columns in 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 passMyArray(int[][] myArray)

The ________ method removes an item from an ArrayList at a specific index

remove

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

size

A(n) ________ is used as an index to pinpoint a specific element within an array

subscript

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

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

true

The sequential search algorithm

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

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

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

will allow valid subscripts in the range of 0 through 9, declares array1 to be a reference to an array of double values, and creates an instance of an array of 10 double values

The binary search algorithm

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

A partially filled array is normally used

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

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

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, will allow valid subscripts in the range of 0 through 9, and creates an instance of an array of 10 long values

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

false

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

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


Conjuntos de estudio relacionados

BCABA Terms & Explanations Part 1

View Set

MGMT 3000H Review Questions- Lyons

View Set

Study.com Financial Accounting Chapter 3

View Set

chapter 50 52, adult nursing endocrine and biliary disorder

View Set

Intake Questions Master Practice Quiz

View Set

Characterization, Theme, and Irony in "The Gift of the Magi"

View Set