Computer Science Contest #0809-01 Key October 13, 2018 1) C 21) B 2) B 22) D 3) B 23) B 4) C 24) E 5) A 25) C 6) E 26) A 7) A 27) D 8) B 28) A 9) E 29) A 10) C 30) E 11) C 31) A 12) C 32) B 13) B 33) C 14) A 34) A 15) D 35) B 16) A 36) E 17) D 37) B 18) E 38) D 19) C 39) 10000011 20) E 40) -7 Note to Graders: • All provided code segments are intended to be syntactically correct, unless otherwise stated (e.g. error is an answer). Ignore any typographical errors. • Any necessary Standard Java 2 Packages are assumed to have been imported as needed. • Assume any undefined (undeclared) variables have been defined as used. © A+ Computer Science – www.apluscompsci.com 1. A216 (16210) + 3416 (5210) = D616 (21410), which is equal to 3268. 2. Following order of operations, 3 % 4 = 3, 5 + 3 = 8. 3. The integer will have 6 zeroes preceding the number since it is 2 digits, then the number, then a comma and a space, and then the string will follow. 4. .substring(0) returns the original string and not an error. 5. Boolean z will equal false since 5 = 5 and boolean y will equal true since 13 ≥ 5 resulting in the output of true. 6. The value of w rounding down is 5 and 5 + 5 + 0.1 = 10.1 7. Following order of precedence, var will result in a value of 395. 8. The last let++ in the print statement is executed after the value is printed. 9. The default case is executed for each iteration since the cases are referring to the character values of ‘1’ and ‘4’ instead of integer values, so the default case will be run for each number. 10. The number 6 is at position 3 in array, 9 is at position 6, and 5 is at position 9 resulting in the output of 6 (5 + 1). 11. .next() does not put spaces between elements. 12. The loop is iterated 33 times and stopped when u = 21, setting y to 33. 13. In the Java Order of Precedence, bitwise or has the lowest precedence of all the answer choices. 14. A java integer has a size of 32 bits. 15. .remove() deletes the first object equal to “Chicago”. 16. .compareTo() returns the difference between the strings’ lengths if there is no character where they differ. 17. .pop() in a stack removes the object at the top of the stack and .remove(1) deletes the object at the index 1. 18. native is a Java keyword. 19. cx[0][2] = 1 and cx[3][0] = 2. 20. An error is returned since x has not been initialized before the do while loop. 21. this.name refers to the instance variable name. 22. 9.99 * 5 = 49.95. 23. m2.toString() still executes the .toString() in class Documentary. 24. s[2] = “st” and s[6] = “n”. 25. When c = 9, calc[c-1]++ still increments the value at index 8. 26. A 60° angle has a cosine of 0.5. 27. predict(4) = 421102102. 28. predict(11) = 1152121842115212102102102102021021. 29. This is an example of xor swapping, but since a and e both = 10, their values don’t change after the for loop is executed. 30. The method, like insertion sorts, iterates through each element to find the location it belongs to in the sorted array. 31. The two nested loops in an insertion sort make an approximate runtime of O(n^2) for the worst case. The for loop at the beginning of the method does not make the runtime O(n^3). 32. The method sorts in descending order so when a = 3, re = [50, 40, 30, 10, 20, 60]. 33. Through numeric promotion, the integer 10 is converted to 10.0. 34. ParseLong converts string values to long values in base 10. 35. .remove(“B”, 7.2) does not remove the value at “B” since it does not equal 7.2. 36. While some examples of the other types of graphs may have all pairs of vertices connect by an edge, all complete graphs follow this rule. 37. Like the truth table, not A or B is only false when A = true and B = false. 38. In in-order traversals, the left child of the node is visited first, then the node, then its right child. 39. 12510 = 011111012 and -12510 = 100000112 40. The postfix expression is represented as ((1 - 5 * 7 + (1 + 3) / 2 + 5 * 2) * 3 + 9 * 6 - (9 - 3 + 2) - 4) / 2 + 6 - 1 as an infix expression. The result is -7. © A+ Computer Science – www.apluscompsci.com