Chapter 7: Arrays and the ArrayList Class

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

T/F - An array's size declarator can be a negative integer expression.

False

T/F - The first size declarator in the declaration of a two-dimensional array represents the number of columns. The second size declarator represents the number of rows.

False

This is the MAXIMUM number of comparisons performed by the sequential search on an array of N elements (assuming the search values are consistently found). a) 2N b) N c) N^2 d) N/2

N

This is the typical number of comparisons performed by the sequential search on an array of N elements (assuming the search values are consistently found).

N/2

T/F - A two-dimensional array has multiple length fields.

True

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

True

T/F - Both of the following declarations are legal and equivalent: int[] numbers; int numbers[];

True

T/F - Java does not allow a statement to use a subscript that is outside the range of valid subscripts for an array.

True

T/F - The Java compiler does not display an error message when it processes a statement that uses an invalid subscript.

True

T/F - The subscript of the last element in a single-dimensional array is one less than the total number of elements in the array.

True

T/F - The values in an initialization list are stored in the array in the order that they appear in the list.

True

T/F - When an array is passed to a method, the method has access to the original array.

True

To insert an item at a specific location in an ArrayList object, you use this method. a) store b) insert c) add d) get

add

To store an item in an ArrayList object, use this method. a) store b) insert c) add d) get

add

Consider searching for a given value in a sorted array. Under which of the following circumstances will sequential search be faster than binary search? a) The value is not in the array. b) The value is the first element in the array. c) The value is the last element in the array. d) The value is in the middle element of the array. e) Sequential search will never by faster than binary search

b) The value is the first element in the array.

This search algorithm repeatedly divides the portion of an array being searched in half.

binary search

When initializing a two-dimensional array, you enclose each row's initialization list in... a) braces b) parentheses c) brackets d) quotation marks

braces

Which of the following correctly assigns the elements of the colors array to colorList? Choose A, B, C, D, or E below. The final ordering of colors in colorList should be the same as in the colors array. C I for (int i=0; i < colors.length; i++) colorList.add (i, colors.get(i)); II for (int i = colors.length-1; i >= 0; i--) colorList.add(i,colors[i]); III for (int i=0; i < colors.length; i++) colorList.add (colors[i]); a) I only b) II only c) III only d) II and III only e) I, II, and III

c) III only

Write a statement that creates the following 2D array: A double array with 4 rows and 8 columns referenced by the variable candyTypes.

double [ ] [ ] candyTypes = new double[4][8];

Which of the following correctly initializes an array arr to contain four elements each with value 0? I int [ ] arr = {0, 0, 0, 0}; II int [ ] arr = new int [4]; III int [ ] arr = new int [4]; for (int i = 0; i < arr.length; i++) arr[i] = 0; a) I only b) III only c) I and III only d) II and III only e) I, II, and III

e) I, II, and III

Write code that copies array A to array B.

for (int i = 0; i < A.length; i++) b[i]=a[i];

Write a loop that displays the first character of the strings stored in the array shown below. String[ ] petNames = { "Spot", "Duke", "Girl", "Poochie" }

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

This array field holds the number of elements that the array has. a) size b) elements c) length d) width

length

The first subscript in an array is always... a) 1 b) 0 c) -1 d) 1 less than the number of elements

0

The last subscript in an array is always... a) 100 b) 0 c) -1 d) 1 less than the number of elements

1 less than the number of elements

To delete an item from an ArrayList object, you use this method. a) remove b) delete c) erase d) get

remove

This search algorithm steps through an array, comparing each item with the search value.

sequential search

To determine the number of items stored in an ArrayList object, you use this method. a) size b) capacity c) items d) length

size

This indicates in an array declaration the number of elements that an array is to have a) subscript b) size declarator c) element sum d) reference variable

size declarator

Each element of an array is accessed by a number known as a(n)... a) subscript b) size declarator c) address d) specifier

subscript

Array bounds checking happens... a) when the program is compiled b) when the program is saved c) when the program runs d) when the program is loaded into memory

when the program runs


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

CHAPTER 6 - ENTREPRENEURSHIP AND STARTING A SMALL BUSINESS

View Set

EMT-B Chapter 36 - Transport Operations

View Set

(Lab quiz) Exercise 8: Overview of the skeleton-classification and structure of bones and cartilages

View Set

Chapter 9: Pain Management during Labor and Birth

View Set

Introduction to Criminal Justice study guide for 1,4

View Set

Community Health Exam 2 (8, 9, 12, 13)

View Set

ATI: Quiz #21 Dementia and Losses

View Set

Module 11: Banking and the Federal Reserve System

View Set