60/66 = 91%

Before the AP Exam, I need to revise enhanced for loops, and looping through 2D arrays. I understand logic gates/de morgans laws, but I need more practice with it

Question 20

  • A - Incorrect. The given code segment prints 1357, while this code segment prints 0246.

  • B - Incorrect. The given code segment prints 1357, while this code segment prints 0246.

  • c - Incorrect. The given code segment prints 1357, while this code segment prints 13579.

  • D - Incorrect. The given code segment prints 1357, while this code segment prints 246.

  • E - Correct. The given code segment starts when k is 1 and prints every other value as long as k is less than or equal to 7. This code segment starts when k is 1 and prints every other value as long as k is less than or equal to 8. Both code segments print 1357.

cb1

Question 37

  • A - Incorrect. The statement assigns a different value to b2 than the code segment assigns to b1 when num is between -100, exclusive, and 0, inclusive, or when num is less than -100.

  • B - Incorrect. The statement assigns true to b2 for all values of num.

  • C - Incorrect. The statement assigns a different value to b2 than the code segment assigns to b1 when num is between 0 and 100, exclusive, or when num is greater than 100.

  • D - Incorrect. The statement assigns a different value to b2 than the code segment assigns to b1 when num is between 0 and 100, exclusive.

  • E - Correct. In the body of the first if clause in the code segment, b1 retains the value true if num is between 0 and 100, exclusive. In the body of the else clause, b1 retains the value true if num is less than -100. The statement assigns true to b2 if num is less than -100 or between 0 and 100, exclusive.

cb2

Question 40

  • A - Incorrect. Careless mistake, we need to return the element in nums array, not numVal

  • B - Correct. This options correctly checks whether numVals is 1, and then accesses the elements in nums array

cb3

Question 44

  • A - Incorrect. A constructor signature consists of the constructor name and the parameter list. A correct constructor header does not include a return type.

  • B - Incorrect. Assigning int values to double variables is allowed, although assigning double values to int variables is not allowed.

  • C - Incorrect. The void return type of the incrementPoints method is correct because the method does not return a value.

  • D - Correct. The variables n1 and n2 are not instance variables of the Points class, nor are they defined in the incrementPoints method. The instance variables num1 and num2 should have been used instead of n1 and n2.

  • E - Incorrect. The variable value is the parameter passed to the incrementPoints method. cb4

Question 52

  • A - Incorrect. This line of code increases the value of surcharge by adding price to it; although the revised code will compile, this is not the intended behavior.

  • B - Correct. The raisePrice method is intended to increase the value of price by adding surcharge to it; the statement “price += surcharge” works as intended. The method should not return a value, as it is a void mutator method, not an accessor method.

  • C - Incorrect. The raisePrice method is defined as having return type void, so it should not include a return statement. The revised code will not compile.

  • D - Incorrect. A method definition must specify a return type; failing to do so will cause a compilation error.

  • E - Incorrect. Although the revised code will compile, it will not perform as intended because the statement on line 14 does not change the value of price. cb5

Question 59

  • A - Incorrect. Choice I will return the correct value if the element in the array with one element was target. In this case, with the first call to seqSearchRecHelper the value of data[0] would be target and 0 would be returned. Choice II will eventually cause an ArrayIndexOutOfBoundsException to be thrown when the recursive call is made with target and -1. This will happen after every valid index in data has been examined. During this call, data[-1] is out of bounds.

  • B - Correct. Choice I will return the correct value if the element in the array with one element was target. In this case, with the first call to seqSearchRecHelper the value of data[0] would be target and 0 would be returned. Choice II will eventually cause an ArrayIndexOutOfBoundsException to be thrown when the recursive call is made with target and -1. This will happen after every valid index in data has been examined. During this call, data[-1] is out of bounds. Choice III will correctly return the index of the element closest to the end of the array with the value target, since data[last] == target will be true at some valid index value of last.

  • C - Incorrect. Choice II will eventually cause an ArrayIndexOutOfBoundsException to be thrown when the recursive call is made with target and -1. This will happen after every valid index in data has been examined. During this call, data[-1] is out of bounds. Choice III will correctly return the index of the element closest to the end of the array with the value target, since data[last] == target will be true at some valid index value of last.

  • D - Incorrect. Choice I will return the correct value if the element in the array with one element was target. In this case, with the first call to seqSearchRecHelper the value of data[0] would be target and 0 would be returned.

  • E - Incorrect. Choice I will return the correct value if the element in the array with one element was target. In this case, with the first call to seqSearchRecHelper the value of data[0] would be target and 0 would be returned. Choice III will correctly return the index of the element closest to the end of the array with the value target, since data[last] == target will be true at some valid index value of last.

cb6