Score: 38/52

This is an image

Corrections:

Question 1

This is an image

Topic 8.1: 2D Arrays Topic 8.2: Traversing 2D Arrays

The correct answer is B: 8. ArrayIndexOutOfBoundsException after 8 iterations because the columns are numbered 0 to 7 and does not include 8.

Question 5

This is an image

Topic 8.2: Traversing 2D Arrays

The correct answer is E: {F J}{G K}{H L}. The code traverses through the array beginning with the second row and second column. The print line then prints what is after that.

Question 13

This is an image

Topic 3.5: Compound Boolean Expressions

The correct answer is A: x. If an expression is x or y but also x it has to be x.

Question 10

This is an image

Topic 2.6: String Objects - Concatenation, Literals, and More

The correct answer is D: 0008. The first line initialized str as 0. Then the second adds 008 to what the string already had to result in 0008.

Question 16

This is an image

Topic 7.3: Traversing ArrayLists

The correct answer is D: 4. Counts the number of elements with the letter a. apple, banana, orange, pear. Total of 4.

Question 23

This is an image

Topic 7.3: Traversing ArrayLists

The correct answer is D: / * expression * / / / * condition * /listOfWords.size() / k != sizeOfList - 1. It takes the size of the array and adds a comma between each element of the arraylist. A comma is not added after the last term which is why k != sizeOfList - 1.

Question 25

This is an image

Topic 2.7: String Methods Topic 7.4: Developing Algorithms Using ArrayLists

The correct answer is B: [“bear”, “zebra”, “bass”, “cat”, “koala”, “baboon”]. Items starting with b are removed then added back to the same place they were removed from therefore keeping the array list the same.

Question 27

This is an image

Topic 2.7: String Methods Topic 4.3: Developing Algorithms Using Strings

The correct answer is C: “optr”. k starts at 1 so prints every other letter of computer starting with the “o”. “cmue” would be correct if k started at 0.

Question 29

This is an image

Topic 2.6: String Objects - Concatenation, Literals, and More

The correct answer is D: It is true that the world’s athletes competed in Olympic Games in 1988 but false that the world’s athletes competed in Olympic Games in 1990. True compiles as it is a boolean so it does not need quotation marks.

Question 42

This is an image

Topic 2.7: String Methods Topic 4.3: Developing Algorithms Using Strings

The correct answer is E: mystery (“noon”). The method extracts the letters in reverse order through the for loop. It then compares str to temp and if they are the same it returns true. Since noon is the same forward and backward, the algorithm will return true.

Question 39

This is an image

Topic 7.3: Traversing ArrayLists

The correct answer is B: Replace line 14 with price += surcharge;. In order to add subcharge to price, the price needs to then become the previous price plus subcharge making price += subcharge the correct function to do so. Since it is a void mutator method, and not an accessor method, the method should not return a value.

Question 54

This is an image

Topic 10.1: Recursion

The correct answer is E: The code segment skips some elements of myList because the indexes of all subsequent elements change by one when a list element is removed. When one element is removed the rest of the elements move up and their value changes.

Question 40

This is an image

Topic 7.3: Traversing ArrayLists

The correct answer is C: III only. Move backwards to ensure that the value of each element is not changing so that nothing gets skipped.

Question 41

This is an image

Topic 7.3: Traversing ArrayLists

The correct answer is E: The method skips some elements of numList during the traversal. Elements are shifted after removal.

Question 42

This is an image

Topic 7.3: Traversing ArrayLists

The correct answer is D:[0, 4, 2, 5, 3]. I am still confused why the first 0 does not get removed.

Question 44

This is an image

Topic 2.7: String Methods Topic 6.4: Developing Algorithms Using Arrays

The correct answer is D: {“of”, “of”, “of”, “spring”}. The shortest string is assigned of and the last iteration has to be string.

Question 45

This is an image

Topic 2.7: String Methods Topic 6.4: Developing Algorithms Using Arrays

The correct answer is A: 4. Line 12 is executed each time a new smallest value is found which is 4 times.

Notes

  • set method for array lists (k, “alex”)
    • replaces the value at the k integer spot with alex
    • returns what was previously in the spot
  • substring(int beginIndex, int endIndex)
    • includes begin, excludes end
  • arr.length = number of rows
  • make sure to check if the values assigned to elements changes