Programming 2 Chapter 7, 8, and 9

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

What would 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.

Which of the following is a valid delcaration 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

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

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

False

In order to do a binary search on an array

The array must be sorted, the values must be numeric, and you need to perform a sequential search to be sure that the element you are looking for is there.

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

The code contains a sytnax error and will not compile.

An ArrayList automatically expands in size to accommodate the items stored in it. T/F

True

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

True

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

True

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

True

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

remove

You can use the ________ method to replace an item at a specific location in an ArrayList.

set

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

subscript

Java provides a mechanism known as a ________, which makes it possible to write a method that takes a variable number of arguments.

variable-length argument list

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}. {99, 69, 21, 43}, {88, 95, 92, 94}, {91, 84, 88, 96} };

94

A search algorithm

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

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

The value variable will contain the lowest value in the numbers array.

Which of the following import statements is required in order to use the ArrayList class?

import java.util.ArrayList

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. add


Conjuntos de estudio relacionados

PSYCH 100 - Module 49 -- Mood disorders

View Set

Nurs 472 Final Prep U Quiz Collection

View Set

American Red Cross Basic Life Support Final Exam

View Set

Abnormal Psychology: Positive Emotions

View Set

Art: A Brief History - Chapter 3: Art of Ancient Egypt

View Set

International Business Chapter 13 Brian Rawson

View Set

I&B Exam 1 Book Self-Assessment Questions

View Set