csa unit 7

Ace your homework & exams now with Quizwiz!

Which of the following represents the value of scales after the code has been executed? a. [SO, RE, FA, DO] b. [SO, RE, MI, FA, DO] c. [SO, RE, MI, DO] d. [FA, RE, MI, DO] e. [FA, SO, RE, MI, DO]

b.

What will the following code print? a. 0 b. 5 c. 6 d. 9 e. 15

c.

Which of the following represents the value of nums after the code segment has been executed? a. [20, 40, 90, 50] b. [10, 20, 30, 40, 50] c. [20, 30, 90, 50] d. [20, 40, 50, 90] e. [20, 30, 80, 50]

c.

A company organizes all of its client database in order of the amount of money that the account is worth. When a new account is added, it is placed in the correct order in the database based on the worth of the account. Which classic algorithm would be best suited to perform this function? a. Linear/Sequential Search b. Insertion Sort c. Selection Sort d. None of these are viable options

b.

A website organizes its list of contributors in alphabetical order by last name. The website's new manager would prefer the contributor list to be ordered in reverse alphabetical order instead.. Which classic algorithm would be best suited to complete this task? a. Linear/Sequential Search b. Selection Sort c. Insertion Sort d. None of these algorithms are viable options.

b.

Given an ArrayList initialized with the values [6, 5, 4, 3, 2, 1], how many times does Line 19 execute when the ArrayList is sorted using the selection sort algorithm? a. 6 b. 3 c. 5 d. 30 e. 4

b.

What is wrong with the following code? a. It will throw an IndexOutOfBoundsException. b. You cannot use int as the type in an ArrayList. c. list is a reserved word, so you can't call the variable that. d. You need to define the new ArrayList on a new line of code. e. Nothing. The above code is correct.

b.

What would the proper initialization and declaration be for an ArrayList myTemps meant to store precise temperature measurements? a. ArrayList<double> myTemps = new ArrayList<double>(); b. ArrayList<Double> myTemps = new ArrayList<Double>(); c. ArrayList<Integer> myTemps = new ArrayList<Integer>(); d. ArrayList<double> myTemps = ArrayList<double>(); e. ArrayList<Double> myTemps = ArrayList<Double>();

b.

How many times is the statement on Line 13 executed as a result of the call to insertionSort? a. 5 b. 30 c. 15 d. 16 e. 6

c.

What is printed when the code segment is executed? a. [9, 8, 7, 6, 5] b. [10, 9, 8, 7, 6] c. [9, 8, 7, 6] d. [9, 8, 7, 6, 4, 3] e. Nothing will print, as the while loop condition occurs infinitely.

c.

What is printed when the code segment is executed? a. [] b. ["Two", "Four"] c. ["Two", "Four", "Six"] d. ["Four", "Five", "Six"] e. ["Six"]

c.

What value would be returned from the call search(nums, 4)? a. -1 b. 2 c. 4 d. This search method is written improperly, and will result in an error. d. 3

c.

What would be the most effective way to alter this selection sort algorithm so that an ArrayList would be sorted from greatest to smallest value? a. Change Line 3 to int currentMaxIndex; b. Change Line 5 to for(int i= arr.size() -1; i > 0; i --) c. Change Line 10 to if(arr.get(j) > arr.get(currentMinIndex)) d. Change Line 16 to if (i > currentMinIndex) e. Change Line 19 to arr.set(arr.get(i), currentMinIndex);

c.

Which of the following Lines needs to be modified in order for the method to work as intended? a. Line 1 - The method should be returning a String value, not an int. b. Line 4 - The loop should go to < list.size() - 1 so as to avoid an IndexOutofBoundsException. c. Line 8 - The return should be the counter, not list.get(counter). d. Line 10 - As written, the counter will skip every other value. e. Line 12 - The return value should be a String, not an int.

c.

What is the proper way to get the number of items in an ArrayList called list? a. list.length b. list.size c. list.length() d. list.size()

d.

What will the following code print? a. "Hello" b. "World" c. "list[0]" d. There will be a compiler error e. None of the above

d.

What will the following code print? a. 3 b. coding c. in d. Java e. It will throw an IndexOutOfBoundsException.

d.

Which of the following can be replaced with /* Missing Code */ so that the statement works as intended? a. I only b. III only c. I and III d. II and III e. I, II, and III

d.

The method as written, however, is incorrect. Which ArrayList(s) list would prove that this method was written incorrectly? a. III only b. II and IV c. II only d. I and IV e. II and III

e.

What is printed as a result of this code segment? a. [10, 15, 20, 25, 30] b. [5, 15, 20, 25, 30] c. [1, 2, 3, 4, 5] d. [5, 10, 15, 20, 30] e. An IndexOutofBoundsException occurs.

e.


Related study sets

Chapter 55: Management of Patients With Urinary Disorders

View Set

Chapter 6: values, ethics, and advocacy PrepU questions

View Set

AP Macroeconomics: GDP, Inflation, Unemployment Quiz

View Set

Commonlit - MASLOW'S HIERARCHY OF NEEDS

View Set

Volume of cubes and rectangular prisms, Volume of rectangular prisms, Money

View Set