comp sci data structures

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

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; What is the value of something[2].length?

5

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; What is the value of something[1][2]?

1.3

What value will be held in mysteryNumber when this code finishes running? int mysteryNumber = 0; String[] mysteryArray = {"Finn", "Jake", "Bubblegum"}; for(int i = 0; i < mysteryArray.length; i++) { mysteryNumber += mysteryArray[i].length(); }

17

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; What is the value of something[2][1]?

2.3

Which of the following are valid arrays? I. int[] coolArray = {1, 2, 3}; II. int[] threeThings = {1.0, 2.0, 3.0}; III. int[] = {"1", "2", "3"};

I only

What will the following code print? ArrayList<String> list = new ArrayList<String>(); list.add("I"); list.add("love"); list.add("coding"); list.add("in"); list.add("Java"); list.remove(3); System.out.println(list.get(3));

Java

Which of the following arrays has a length of 5?

None of the above

What will the Array gameBoard contain after this code runs? int WIDTH = 3; int HEIGHT = 3; String[] gameBoard = new String[WIDTH * HEIGHT]; for(int m = 0; m < HEIGHT; m++) { for(int n = 0; n < WIDTH; n++) { int someNumber = m * WIDTH + n; if(someNumber % 3 == 0) { gameBoard[someNumber] = "X"; } else { gameBoard[someNumber] = "O"; } } }

["X", "O", "O", "X", "O", "O", "X", "O", "O"]

We want to create a 2D double array with 6 rows and 7 columns and assign it to connectFour. Which of these is correct?

double[][] connectFour = new double[6][7]

Given the following: String[][] poem = { {"I", "am", "the", "cookie", "monster."}, {"Would", "you", "like", "a", "cookie?"}, {"COOOOKIE", "OM", "NOM", "NOM", "NOM"} } Which of the following code fragments would produce the following output? I am the cookie monster. Would you like a cookie? COOOOKIE OM NOM NOM NOM.

for (int line = 0; line < poem.length; line++) { for (int word = 0; word < poem[line].length; word++) { System.out.print(poem[line][word] + " "); } System.out.println() }

Which is the correct way to construct and assign a 2D array, with 8 rows and 10 columns, to the variable popcorn?

int[][] popcorn = new int[8][10];

What would be a correct way to instantiate this 2D array?

int[][] table = { {1, 0, 10, 0}, {3, 8, 38, 0} };

What is the proper way to get the number of items in an ArrayList called list?

list.size()

What values will the array contain after the following the code is run? int[] someArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; for (int i = someArray.length - 2; i >= 0; i-=2) { someArray[i] = someArray[i] - 5; }

{1, -3, 3, -1, 5, 1, 7, 3, 9, 5, 11}

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; What is the value of something.length?

3

What will the following code print? ArrayList<Integer> list = new ArrayList<Integer>(); list.add(0); list.add(1); list.add(2); list.add(3); list.add(4); list.add(5); int sum = 0; for (int i = 0; i < list.size(); i+= 2) { sum += list.get(i); } System.out.println(sum);

6

You are working at the frozen yogurt shop in the mall. Your boss asks you to count how many flavors have the word chocolate in their name. You begin going through the list of flavors, but quickly realize that their are over 9000 flavors to check! Luckily, your boss stored all of the different flavors in a Java Array named flavorArray on the company computer. Write a Java program to count the number of flavors that have chocolate in their name.

int chocolateFlavorCount = 0; for(int i = 0; i < flavorArray.length; i++) { if(flavorArray[i].contains("chocolate")) { chocolateFlavorCount++; } } System.out.println(chocolateFlavorCount);

What will the following code print? ArrayList<String> list = new ArrayList<String>(); list.add("Hello"); list.add("World"); System.out.println(list[0]);

There will be a compiler error

What is wrong with the following code? ArrayList<int> list = new ArrayList<int>(); list.add(1); System.out.println(list.get(0));

You cannot use int as the type in an ArrayList.

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; We want to replace the row {6.1, 10.2, 1.3, -2.5, -9.9} with a complete new array that looks like {3.1, 4.1, 5.9, 2.6, 8.4}.

double[] temp = {3.1, 4.1, 5.9, 2.6, 8.4}; something[1] = temp;

What is the output of the following program? public class SayHello { public void run() { String stringArray[] = {"h", "e", "l", "l", "o", "w"}; for(int i=0; i <= stringArray.length; i++) { System.out.print(stringArray[i]); } } }

error

When run, which of the following yields the integer 5?

int[] anotherArray = {5, 10, 15, 20, 25}; System.out.println(anotherArray[(anotherArray.length - 2)] - 15);

Given the following: double[][] something = { {2.5, 6.8, 8.3, 2.3, 0.0}, {6.1, 10.2, 1.3, -2.5, -9.9}, {1.1, 2.3, 5.8, 13.21, 34.55} }; How do you replace the value 13.21 with 8.8?

something[2][3] = 8.8;


Conjuntos de estudio relacionados

Vertebrate Form and Function Exam 3

View Set

#3: Chemical Reactions within Living Organisms

View Set

Chapter 18 - Eating & Feeding Disorders (Psych) EAQ's

View Set

biology: ch 1 - 7 (semester 1 final)

View Set

CHAPTER 9 TELEVISION COMM180 EXAM #3

View Set

Cardiovascular Target ATI Assessment

View Set

KINE 232 - Athletic Injury Management

View Set