CTP 150 quiz 6

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

which code fragments constructs an array list named players that is initialized to contain the strings "Player 1" and "Player 2"

ArrayList<String> players = new ArrayList<String>(); players.add("Player 1"); players.add("Player 2");

which of the following will create an array, capable of storing 20 Student objects?

Student roster[] = new Student [20];

int m = 0; for (BankAccount a : accounts) { if (a.getBalance() >= atLeast) m++; } what is the purpose of this algorithm?

counting matches

which of the following is a valid declaration for a ragged array, after which you would declare each row?

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

double [][] numbers = new int [6] [9]; given the following 2d array declaration, which statement is true?

the array numbers has 6 rows and 9 columns

ArrayList<String> list = new ArrayList<String>(100); which of the following is not true?

when the 101th item is added, the ArrayList object can not hold the new item

What would be the results after the following code was executed? int x[] = {23, 55, 83, 19}; int y[] = {36, 78, 12, 24}; y = x; x = y;

x[] = {23, 55, 83, 19} and y[] = {23, 55, 83, 19}

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

Fill in the blank for this algorithm for finding a minimum value in an array. double b = ____________________; for (int i = 1; i < accounts.length; i++) { BankAccount a = accounts[i]; if (a.getBalance() < b) b = a.getBalance(); } return b;

accounts[0].getBalance()

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

add

how do you determine the number of columns in a 2d array named board?

board[0].length

assume that the ArrayList has been declared and initialized, complete the following code to retrieve the last value of the array list that stores integers. int lastValue = _______

data.get(data.size() -1)

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 elements of the columns in the array and display values of sum for each column?

for (int col = 0; col < numbers[0].length; col++) { total = 0; for (int row = 0; row < numbers.length; row++) total += numbers[row][col]; System.out.println("Total sum: " + sum); }

if numbers is a 2d int array that has been initialized, which of the following displays the value in column order?

for (int col = 0; row < number[0].length; col++) for(int row = 0; col < numbers.length; row++) System.out.println(numbers[col][row]);

the following statement creates an ArrayList object. what is the purpose fo the <BankAccount> notation? ArrayList<BankAccount> arr = new ArrayList<BankAccount>();

it specifies that only BankAccount may be stored in the ArrayList object

if numbers is a 2d array, which of the following would give the number of rows in the array?

numbers.length

which statement replaces the third element in an ArrayList named players?

players.set(2, "Sally");

which of the following is a correct method header for returning a 2d array from the method?

public static int [ ] [ ] returnArray()

he following search process is called a(n) ____________________ search through the array list. public BankAccount find(int accountNumber) { for (BankAccount a : accounts) { if (a.getAccountNumber() == accountNumber) // Found a match return a; } return null; // No match in the entire array list }

sequential / linear

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

size


Conjuntos de estudio relacionados

AP Chemistry: Unit 3 College Board Questions

View Set

Tempkin: Thyroid and Parathyroid

View Set

History of Graphic Design Chapters 19-21 Test Review

View Set

Florida Statues, Rules, and Regulations

View Set

Sorry, no manipulations with clipboard allowed

View Set

Social Psych: Chapter 12 (Prosocial Behavior), Social Psych Final Chap 11, Social Psych Exam #2 Ch.11, Social Psychology Exam 4, Social Psych Exam 4 SCCC

View Set

ECON Lesson 3.4: Corporations and The Stock Market

View Set